-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
144 changed files
with
8,850 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
*name:A+B | ||
*LANG:C++ | ||
*/ | ||
#include <cstdio> | ||
using namespace std; | ||
int main(){ | ||
int a,b;scanf("%d %d",&a,&b); | ||
printf("%d\n",a+b); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
*Name: Domino | ||
*LANG: C++ | ||
*Source: sgu101 | ||
*/ | ||
#include <cstdio> | ||
#include <cstdlib> | ||
#include <cstring> | ||
#include <iostream> | ||
#include <fstream> | ||
using namespace std; | ||
|
||
struct node{ | ||
int v,next; | ||
}e[250]; | ||
int v[10],t[10],pre[250]; | ||
bool visit[250]; | ||
int path[250],pathNum; | ||
int n,x,y,edgeNum; | ||
|
||
void insert(int a,int b){ | ||
e[++edgeNum].v=b;e[edgeNum].next=v[a];v[a]=edgeNum;t[a]++;t[b]++; | ||
e[++edgeNum].v=a;e[edgeNum].next=v[b];v[b]=edgeNum;t[a]++;t[b]++; | ||
} | ||
void dfs(int pos){ | ||
if (t[pos]==0) {path[++pathNum]=pos;return;} | ||
int j=v[pos]; | ||
while (j!=0){ | ||
if (visit[(j+1)/2]){ | ||
visit[(j+1)/2]=false; | ||
t[pos]--;t[e[j].v]--; | ||
dfs(e[j].v); | ||
} | ||
j=e[j].next; | ||
} | ||
path[++pathNum]=pos; | ||
} | ||
int main(){ | ||
//input | ||
scanf("%d",&n); | ||
for (int i=1;i<=n;++i){ | ||
scanf("%d %d",&x,&y); | ||
insert(x,y); | ||
} | ||
//solve | ||
int tmp=0;int pos=-1,pos1=-1; | ||
for (int i=0;i<=6;++i) t[i]/=2; | ||
for (int i=6;i>=0;--i) | ||
if (t[i] % 2==1) {tmp++;if (t[i]!=0) if (pos==-1) pos=i; else pos1=-1;} | ||
if (pos==-1) | ||
for (int i=0;i<=6;++i) | ||
if (t[i]!=0) {pos=i;break;} | ||
if (tmp!=2 && tmp!=0){ | ||
printf("%s\n","No solution"); | ||
return 0; | ||
} | ||
else{ | ||
memset(visit,true,sizeof(visit)); | ||
dfs(pos); | ||
} | ||
memset(visit,true,sizeof(visit)); | ||
if (pathNum!=(n+1)) {printf("%s\n","No solution");return 0;} | ||
for (int i=1;i<pathNum;++i){ | ||
int j=v[path[i]]; | ||
while (j!=0 && (e[j].v!=path[i+1] || visit[(j+1)/2]==false)) | ||
j=e[j].next; | ||
visit[(j+1)/2]=false; | ||
if ((j+1) % 2==0) | ||
printf("%d %c\n",(j+1)/2,'+'); | ||
else | ||
printf("%d %c\n",(j+1)/2,'-'); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
*Name:coprimes | ||
*LANG: C++ | ||
*Source:sgu102 | ||
*/ | ||
#include <cstdio> | ||
#include <cstdlib> | ||
#include <cstring> | ||
#include <cmath> | ||
#include <iostream> | ||
#include <fstream> | ||
using namespace std; | ||
|
||
int ans=1,n; | ||
bool check[10001]; | ||
|
||
int gcd(int a,int b){ | ||
if (a!=0) return gcd(b%a,a); | ||
else return b; | ||
} | ||
int main(){ | ||
//input | ||
scanf("%d",&n); | ||
memset(check,true,sizeof(check)); | ||
//solve | ||
for (int i=2;i<n;++i){ | ||
if (check[i]){ | ||
if (gcd(min(i,n),max(i,n))==1) | ||
ans++; | ||
else | ||
for (int j=2;j*i<n;++j) | ||
check[j*i]=false; | ||
} | ||
else | ||
for (int j=2;j*i<n;++j) | ||
check[j*i]=false; | ||
} | ||
printf("%d\n",ans); | ||
//fout << ans << endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
/* | ||
*Name:Traffic Lights | ||
*LANG:C++ | ||
*source:sgu103 | ||
*/ | ||
#include <cstring> | ||
#include <iostream> | ||
#include <fstream> | ||
#define MAXN 350 | ||
#define MAXM 15000 | ||
#define INF 0x7FFFFFFF/2; | ||
using namespace std; | ||
/* | ||
ifstream fin("test.in"); | ||
ofstream fout("test.out"); | ||
*/ | ||
int s,t,hl,n,m,suck; | ||
struct junction{ | ||
int c,rc; | ||
int t[2]; | ||
}junc[MAXN]; | ||
struct heapType{ | ||
int v,d,p; | ||
}heap[MAXN]; | ||
struct node{ | ||
node *next; | ||
int v,w; | ||
}; | ||
node *g[MAXN]; | ||
int hpos[MAXN]; | ||
|
||
inline void insert(int u,int v,int w){ | ||
node *x = new node; | ||
x->v=v;x->w=w;x->next=g[u];g[u]=x; | ||
} | ||
void init(){ | ||
int i,j,k,u,v,w;char c; | ||
cin >> s >> t; | ||
cin >> n >> m; | ||
for (i=1;i<=n;++i){ | ||
cin >> c >> junc[i].rc >> junc[i].t[0] >> junc[i].t[1]; | ||
junc[i].c=(c=='B')?0:1; | ||
} | ||
memset(g,0,sizeof(g)); | ||
for (i=1;i<=m;++i){ | ||
cin >> u >>v >> w; | ||
insert(u,v,w); | ||
insert(v,u,w); | ||
} | ||
} | ||
void swap(int a,int b){ | ||
heap[0]=heap[a];heap[a]=heap[b];heap[b]=heap[0]; | ||
hpos[heap[a].v]=a;hpos[heap[b].v]=b; | ||
} | ||
void heapUp(int i){ | ||
while (i!=1 && heap[i].d<heap[i/2].d){ | ||
swap(i,i/2); | ||
i/=2; | ||
} | ||
} | ||
void heapDown(){ | ||
int i=2; | ||
while (i<=hl){ | ||
if (i<hl && heap[i+1].d<heap[i].d) ++i; | ||
if (heap[i].d<heap[i/2].d){ | ||
swap(i,i/2); | ||
i*=2; | ||
} | ||
else break; | ||
} | ||
} | ||
void relax(int u,int v,int w){ | ||
int tmp=heap[hpos[u]].d,time=0; | ||
int t1=junc[u].c,t2=junc[v].c,t3=junc[u].rc,t4=junc[v].rc; | ||
|
||
tmp%=(junc[u].t[0]+junc[u].t[1]); | ||
while (tmp>=junc[u].rc){tmp-=junc[u].rc;junc[u].c=1-junc[u].c;junc[u].rc=junc[u].t[junc[u].c];} | ||
junc[u].rc-=tmp; | ||
tmp=heap[hpos[u]].d; | ||
tmp%=(junc[v].t[0]+junc[v].t[1]); | ||
while (tmp>=junc[v].rc){tmp-=junc[v].rc;junc[v].c=1-junc[v].c;junc[v].rc=junc[v].t[junc[v].c];} | ||
junc[v].rc-=tmp; | ||
|
||
suck=0; | ||
while (junc[u].c!=junc[v].c){ | ||
suck++; | ||
if (suck>3) break; | ||
if (junc[u].rc>junc[v].rc){ | ||
junc[u].rc-=junc[v].rc; | ||
time+=junc[v].rc; | ||
junc[v].c=1-junc[v].c; | ||
junc[v].rc=junc[v].t[junc[v].c]; | ||
} | ||
else if (junc[u].rc<junc[v].rc){ | ||
junc[v].rc-=junc[u].rc; | ||
time+=junc[u].rc; | ||
junc[u].c=1-junc[u].c; | ||
junc[u].rc=junc[u].t[junc[u].c]; | ||
} | ||
else{ | ||
time+=junc[u].rc; | ||
junc[v].c=1-junc[v].c; | ||
junc[v].rc=junc[v].t[junc[v].c]; | ||
junc[u].c=1-junc[u].c; | ||
junc[u].rc=junc[u].t[junc[u].c]; | ||
} | ||
} | ||
if (suck<=3 && time+w+heap[hpos[u]].d<heap[hpos[v]].d){ | ||
heap[hpos[v]].p=u; | ||
heap[hpos[v]].d=time+w+heap[hpos[u]].d; | ||
heapUp(hpos[v]); | ||
} | ||
junc[u].c=t1,junc[v].c=t2,junc[u].rc=t3,junc[v].rc=t4; | ||
} | ||
void dijkstra(){ | ||
int u;node * p =0; | ||
for (u=1;u<=n;++u){ | ||
heap[u].v=u; | ||
heap[u].d=INF; | ||
hpos[u]=u; | ||
} | ||
heap[s].d=0;heap[s].p=s;swap(1,s);hl=n; | ||
while (hl>0){ | ||
u=heap[1].v; | ||
swap(1,hl);hl--;heapDown(); | ||
p=g[u]; | ||
while (p!=0){ | ||
if (hpos[p->v]<=hl) relax(u,p->v,p->w); | ||
p=p->next; | ||
} | ||
} | ||
} | ||
void dfs(int x){ | ||
if (x==0) return; | ||
if (heap[hpos[x]].p!=s) | ||
dfs(heap[hpos[x]].p); | ||
cout << " " << x; | ||
} | ||
void print(){ | ||
if (heap[hpos[t]].p==0){ | ||
cout << 0 << endl; | ||
return; | ||
} | ||
cout << heap[hpos[t]].d << endl; | ||
cout << s; | ||
dfs(t); | ||
cout << endl; | ||
} | ||
int main(){ | ||
init(); | ||
dijkstra(); | ||
print(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
*Name:Little shop of flowers | ||
*LANG:C++ | ||
*Source:sgu104 | ||
*/ | ||
#include <cstdio> | ||
#include <cstring> | ||
#define INF -0x7FFFFFFF/2 | ||
using namespace std; | ||
|
||
int a[200][200],ff[200][200]; | ||
int f,v,max=INF; | ||
|
||
void print(int x,int y){ | ||
if (x>0){ | ||
int i=x; | ||
while (ff[x][i]!=y) ++i; | ||
print(x-1,y-a[x][i]); | ||
printf("%d",i); | ||
if (x!=f) printf(" "); | ||
else printf("\n"); | ||
} | ||
} | ||
int main(){ | ||
scanf("%d %d",&f,&v); | ||
for (int i=1;i<=f;++i) | ||
for (int j=1;j<=v;++j) | ||
scanf("%d",&a[i][j]); | ||
for (int i=0;i<=110;++i) | ||
for (int j=0;j<=110;++j) | ||
ff[i][j]=INF; | ||
for (int i=0;i<=v;++i) ff[0][i]=0; | ||
for (int i=1;i<=f;++i) | ||
for (int j=i;j<=v;++j) | ||
for (int k=0;k<j;++k) | ||
if (ff[i-1][k]+a[i][j]>ff[i][j]) | ||
ff[i][j]=ff[i-1][k]+a[i][j]; | ||
for (int i=1;i<=v;++i) | ||
if (max<ff[f][i]) max=ff[f][i]; | ||
printf("%d\n",max); | ||
print(f,max); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
*NAME:DIV 3 | ||
*LANG:C++ | ||
*Source:sgu105 | ||
*/ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int n,ans; | ||
int main(){ | ||
cin >> n; | ||
cout << ((n/3*2)+(n%3==2)) << endl; | ||
} |
Oops, something went wrong.