-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 73402ba
Showing
319 changed files
with
90,478 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,35 @@ | ||
//11:56 - 12 :09 | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
int t,n,*w,*wl; | ||
scanf("%d",&t); | ||
while(t--) | ||
{ | ||
scanf("%d",&n); | ||
w=(int*)calloc(n+1,sizeof(int)); | ||
wl=(int*)calloc(n+1,sizeof(int)); | ||
|
||
for(int i=1;i<=n;i++) | ||
scanf("%d",&w[i]); | ||
for(int i=1;i<=n;i++) | ||
scanf("%d",&wl[i]); | ||
|
||
sort(w+1,w+n+1); | ||
sort(wl+1,wl+n+1); | ||
|
||
int ans=0; | ||
for(int i=1,j=1;i<=n && j<=n;) | ||
{ | ||
if(w[i] <= wl[j]) | ||
{ans++;j++;i++;} | ||
else | ||
j++; | ||
} | ||
free(w); | ||
free(wl); | ||
printf("%d\n",ans); | ||
} | ||
} |
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,55 @@ | ||
//12:11 - 12:23 | ||
// 30 min gone | ||
|
||
#include<bits/stdc++.h> | ||
using namespace std; | ||
struct node | ||
{ | ||
int f; | ||
int num; | ||
}; | ||
|
||
bool so(const node &a, const node &b) | ||
{ | ||
if(a.f == b.f) | ||
return a.num < b.num; | ||
return a.f < b.f; | ||
} | ||
|
||
int main() | ||
{ | ||
int t; | ||
node *can; | ||
scanf("%d",&t); | ||
while(t--) | ||
{ | ||
can = (node*)calloc((10),sizeof(node)); | ||
for(int i=0;i<10;i++) | ||
{ | ||
can[i].num = i; | ||
scanf("%d",&can[i].f); | ||
} | ||
sort(can,can+10,so); | ||
|
||
if(can[0].num == 0 && can[1].f > can[0].f) | ||
{ | ||
printf("1"); | ||
for(int i=1;i<=can[0].f+1;i++) | ||
printf("0"); | ||
printf("\n"); | ||
} | ||
else if(can[0].num == 0 && can[1].f == can[0].f) | ||
{ | ||
for(int i=1;i<=can[1].f+1;i++) | ||
printf("%d",can[1].num); | ||
printf("\n"); | ||
} | ||
else | ||
{ | ||
for(int i=1;i<=can[0].f+1;i++) | ||
printf("%d",can[0].num); | ||
printf("\n"); | ||
} | ||
free(can); | ||
} | ||
} |
Empty file.
Binary file not shown.
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,4 @@ | ||
3 | ||
2 1 1 4 0 6 3 2 2 2 | ||
0 1 1 1 1 1 1 1 1 1 | ||
2 2 1 2 1 1 3 1 1 1 |
Binary file not shown.
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,24 @@ | ||
//18:08 | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
int t,k,temp,ans; | ||
char s[1<<16+1]; | ||
scanf("%d",&t); | ||
while(t--) | ||
{ | ||
scanf("%d",&k); | ||
scanf("%s",s); | ||
|
||
for(int i=0;i<(1<<k) ; i++) | ||
{ | ||
ans =0; | ||
for(int j=0;j<k;j++) | ||
ans |= ((i>>j)&1)<<(k-j-1); | ||
printf("%c",s[ans]); | ||
} | ||
printf("\n"); | ||
} | ||
} |
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 @@ | ||
//17:53 - 18:08 | ||
#include<bits/stdc++.h> | ||
|
||
int main() | ||
{ | ||
int t,n,m,tmp,*a; | ||
scanf("%d",&t); | ||
while(t--) | ||
{ scanf("%d %d",&n,&m); | ||
a=(int*)calloc(n+1,sizeof(int)); | ||
for(int i=1;i<=m;i++) | ||
{ | ||
scanf("%d",&tmp); | ||
a[tmp] = 1; | ||
} | ||
bool flip =false; | ||
for(int i=1;i<=n;i++) | ||
{ | ||
if(a[i] == 0) | ||
{ | ||
if(!flip) | ||
{ | ||
printf("%d ",i); | ||
flip = true; | ||
a[i] =1; | ||
} | ||
else | ||
flip = false; | ||
} | ||
} | ||
printf("\n"); | ||
for(int i=1;i<=n;i++) | ||
{ | ||
if(a[i] == 0) | ||
{ | ||
printf("%d ",i); | ||
a[i] = 1; | ||
} | ||
} | ||
printf("\n"); | ||
free(a); | ||
} | ||
} |
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,102 @@ | ||
//19:15 | ||
/* | ||
Modified travelling salesman problem | ||
*/ | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
#define mp(a,b) make_pair(a,b) | ||
int n; | ||
map <int,pair<int,int > > m; | ||
int dist[17][1<<8][1<<8]; | ||
|
||
int dp(int x,int y,int bitc,int bitt,int tp,int id) | ||
{ | ||
int ans=100000000; | ||
int tox,toy,val; | ||
if(bitc == (1<<(n))-1) | ||
{ | ||
|
||
dist[id][bitc][bitt] = x+y; | ||
return x+y; | ||
} | ||
|
||
if(tp < 2) | ||
{ | ||
// picking up another tool | ||
for(int i=0;i<n;i++) | ||
{ | ||
if((bitt >> i) & 1) //we already have the tool | ||
continue; | ||
tox=m[i+n].first; | ||
toy=m[i+n].second; | ||
|
||
if(dist[i+n][bitc][bitt|(1<<i)] >0) | ||
val = dist[i+n][bitc][bitt|(1<<i)]; | ||
else | ||
val = dp(tox,toy,bitc,bitt|(1<<i),tp+1,i+n); | ||
|
||
ans=min(ans,val+(int)(abs(x-tox)+abs(y-toy))); | ||
|
||
|
||
} | ||
} | ||
|
||
if(tp > 0) | ||
{ | ||
// serving the chef | ||
for(int i=0;i<n;i++) | ||
{ | ||
if(((bitt>>i) & 1) && ((bitc >>i) & 1) ==0 ) //we have the tool and chef is not served yet | ||
{ | ||
tox=m[i].first; | ||
toy=m[i].second; | ||
if(dist[i][bitc|(1<<i)][bitt] >0) | ||
val =dist[i][bitc|(1<<i)][bitt]; | ||
else | ||
val = dp(tox,toy,bitc|(1<<i),bitt,tp-1,i); | ||
|
||
ans = min(ans,val+(int)(abs(x-tox)+abs(y-toy))); | ||
|
||
} | ||
} | ||
} | ||
dist[id][bitc][bitt] = ans; | ||
return ans; | ||
} | ||
|
||
int main() | ||
{ | ||
int t,x,y,tox,toy,ans,bitt,bitc; | ||
scanf("%d",&t); | ||
while(t--) | ||
{ | ||
m.clear(); | ||
scanf("%d",&n); | ||
for(int i=0;i<2*n;i++) | ||
{ | ||
for(int j=0;j<(1<<8);j++) | ||
{ | ||
for(int k=0;k<(1<<8);k++) | ||
dist[i][j][k] = 0; | ||
} | ||
} | ||
for(int i=0;i<n;i++) | ||
{ | ||
scanf("%d %d",&x,&y); | ||
m[i] = mp(x,y); | ||
scanf("%d %d",&x,&y); | ||
m[i+n] = mp(x,y); | ||
} | ||
ans=10000000,bitc=0,bitt=0; | ||
for(int i=0;i<n;i++) | ||
{ | ||
tox = m[i+n].first; | ||
toy = m[i+n].second; | ||
|
||
ans=min(ans,dp(tox,toy,bitc,bitt|(1<<i),1,i+n)+tox+toy); | ||
|
||
} | ||
printf("%d\n",ans); | ||
} | ||
} | ||
|
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,12 @@ | ||
3 | ||
2 | ||
1 0 0 1 | ||
0 0 1 1 | ||
3 | ||
0 3 0 1 | ||
0 4 0 2 | ||
0 5 0 3 | ||
3 | ||
0 1 0 2 | ||
0 1 0 2 | ||
0 1 0 2 |
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,88 @@ | ||
//20:17 | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
#define mp(a,b) make_pair(a,b) | ||
#define mpp(a,b,c) mp(a,mp(b,c)) | ||
|
||
vector<vector<pair<int,int> > > g(100001); | ||
vector<pair<bool,pair<int,int> > > e; | ||
int m; | ||
bool VertexCover(int k) | ||
{ | ||
int index = -1,u,v,id; | ||
for(int i=0;i<m;i++) | ||
{ | ||
if(e[i].first) | ||
{ | ||
index = i; | ||
break; | ||
} | ||
} | ||
|
||
if(index == -1) | ||
return true; | ||
|
||
if(k == 0) | ||
return false; | ||
|
||
u = e[index].second.first; | ||
v = e[index].second.second; | ||
// taking u in vc | ||
for(int i=0;i<g[u].size();i++) | ||
{ | ||
id = g[u][i].first; | ||
e[id].first = false; | ||
|
||
} | ||
|
||
bool f = VertexCover(k-1); | ||
|
||
// returning back | ||
for(int i=0;i<g[u].size();i++) | ||
{ | ||
|
||
id=g[u][i].first; | ||
e[id].first = true; | ||
} | ||
|
||
// taking v in vc | ||
for(int i=0;i<g[v].size();i++) | ||
{ | ||
|
||
id=g[v][i].first; | ||
e[id].first = false; | ||
} | ||
bool s = VertexCover(k-1); | ||
// returning back | ||
for(int i=0;i<g[v].size();i++) | ||
{ | ||
id=g[v][i].first; | ||
e[id].first = true; | ||
} | ||
return f|s; | ||
} | ||
|
||
int main() | ||
{ | ||
int t,n,gs,u,v; | ||
scanf("%d",&t); | ||
while(t--) | ||
{ | ||
e.clear(); | ||
scanf("%d %d %d",&n,&m,&gs); | ||
for(int i=0;i<=n;i++) | ||
g[i].clear(); | ||
int vc=n-gs; | ||
for(int i=0;i<m;i++) | ||
{ | ||
scanf("%d %d",&u,&v); | ||
g[u].push_back(mp(i,v)); | ||
g[v].push_back(mp(i,u)); | ||
e.push_back(mpp(true,u,v)); | ||
} | ||
if(VertexCover(vc)) | ||
printf("Possible\n"); | ||
else | ||
printf("Impossible\n"); | ||
} | ||
} |
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,14 @@ | ||
//21:40 | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
int main() | ||
{ | ||
int n,a,sum=0; | ||
scanf("%d",&n); | ||
for(int i=0;i<n;i++) | ||
{ | ||
scanf("%d",&a); | ||
sum+=a; | ||
} | ||
printf("%d\n",max(n,(int)ceil(sum/2.0))); | ||
} |
Oops, something went wrong.