Codeforces Round #385 (Div. 2), problem: (E) Hongcow Buys a Deck of Cards Solution in C/C++

By |2017-04-07T22:11:46+00:00December 18th, 2016|Categories: C/C++, Programming|Tags: , , , , , , , |

#include<bits/stdc++.h> using namespace std; const int maxn=16,INF=0x3f3f3f3f; char type[maxn]; int R[maxn],B[maxn]; char readchar() { for(;;) { char ch=getchar(); if(!isspace(ch)) { return ch; } } } int n; typedef pair<int,int> pii; typedef set<pii> Spii; Spii dp[1<<maxn]; void Insert(Spii& s,const pii& p) { Spii::iterator it=s.lower_bound(p); if(it==s.begin()||(--it)->second>p.second) [...]

Codeforces Round #385 (Div. 2), problem: (D) Hongcow’s Game Solution in C/C++

By |2017-04-07T22:11:47+00:00December 18th, 2016|Categories: C/C++, Programming|Tags: , , , , , , |

#include <limits.h> #include <stdio.h> #define N 1000 void query(int *ww, int *aa, int k, int n) { int i; printf("%d\n", k); for (i = 0; i < k; i++) printf("%d ", ww[i]); printf("\n"); fflush(stdout); for (i = 1; i <= n; i++) scanf("%d", &aa[i]); [...]

Codeforces Round #385 (Div. 2), problem: (C) Hongcow Builds A Nation Solution in C/C++

By |2017-04-07T22:11:47+00:00December 18th, 2016|Categories: C/C++, Programming|Tags: , , |

#include <stdio.h> #include <string.h> int c[1005], p[1005], sz[1005], gov[1005]; int find_parent(int n) { if (p[n] == n) return n; return p[n] = find_parent(p[n]); } int get_full_size(int n) { return n * (n-1) / 2; } int main(int argc, char** argv) { int i, n, [...]

Codeforces Round #385 (Div. 2), problem: (B) Hongcow Solves A Puzzle Solution in C/C++

By |2017-04-08T18:37:51+00:00December 18th, 2016|Categories: C/C++, Programming|Tags: , , |

#include <limits.h> #include <stdio.h> int main() { int i, j, n, m, cnt, imin, jmin, imax, jmax; static char cc[500][501]; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) scanf("%s", cc[i]); imin = jmin = INT_MAX; imax = jmax = 0; cnt [...]

Codeforces Round #385 (Div. 2), problem: (A) Hongcow Learns the Cyclic Shift Solution in C/C++

By |2017-04-07T22:11:47+00:00December 18th, 2016|Categories: C/C++, Programming|Tags: , , |

#include<stdio.h> #include<string.h> void cycle(char s[],int len) { char temp=s[len-1]; int i; for(i=len-1;i>0;i--) { s[i]=s[i-1]; } s[0]=temp; } int main(){ char s[51],orig[51]; int len,count=0; scanf("%s",s); len=strlen(s); strcpy(orig,s); do { cycle(s,len); count++; } while(strcmp(orig,s)); printf("%d\n",count); return 0; }

Codeforces Round #384 (Div. 2), problem: (E) Vladik and cards Solution in C/C++

By |2017-04-07T22:11:47+00:00December 17th, 2016|Categories: C/C++, Programming|

#include <stdio.h> #include <string.h> #define MIN(X,Y) ((X)<(Y) ? (X) : (Y)) int n,c[1010],r[1010][10][1010],dp[10][300][1010]; int solve(int aver,int c,int b,int k); int main(void) { //freopen("cards.in","r",stdin); //freopen("cards.out","w",stdout); scanf("%d",&n); int i,j,k; for(i=1;i<=n;i++) scanf("%d",&c[i]); memset(r,-1,sizeof(r)); int s; for(i=1;i<=n;i++) for(j=1;j<=8;j++) { r[i][j][s=0]=i-1; for(k=i;k<=n;k++) if(c[k]==j) r[i][j][++s]=k; } int min=1,max=n,m,t; while(min<max) { [...]

Codeforces Round #384 (Div. 2), problem: (D) Chloe and pleasant prizes Solution in C/C++

By |2017-04-07T22:11:47+00:00December 17th, 2016|Categories: C/C++, Programming|Tags: , , , , , , , |

#include <stdio.h> #include <string.h> #define MAX(X,Y) ((X)>(Y) ? (X) : (Y)) #define INF 1000000000000000 typedef long long LL; int n,sz,first[200010],next[400010],tail[400010],son[200010],bro[200010],vis[200010]; LL a[200010],s[200010],maxs[200010],maxs2[200010]; void addedge(int u,int v); void dfs(int u); int main(void) { //freopen("prize.in","r",stdin); //freopen("prize.out","w",stdout); scanf("%d",&n); int i; for(i=1;i<=n;i++) scanf("%I64d",&a[i]); int u,v; memset(first,0,sizeof(first)); for(sz=0,i=1;i<=n-1;i++) { [...]

Codeforces Round #384 (Div. 2), problem: (C) Vladik and fractions Solution in C/C++

By |2017-04-07T22:11:47+00:00December 17th, 2016|Categories: C/C++, Programming|Tags: , , , , , , , |

#include<stdio.h> int main(){ long x; scanf("%ld",&x); if(x==1) printf("-1"); else printf("%ld %ld %ld",x,x+1,x*(x+1)); return 0; }

Codeforces Round #384 (Div. 2), problem: (B) Chloe and the sequence Solution in C/C++

By |2017-04-07T22:11:47+00:00December 17th, 2016|Categories: C/C++, Programming|Tags: , , , , , , , |

long long k; main() { scanf("%d%lld",&k,&k); printf("%d\n",1+__builtin_ctzll(k)); }

Codeforces Round #384 (Div. 2), problem: (A) Vladik and flights Solution in C/C++

By |2017-04-07T22:11:47+00:00December 17th, 2016|Categories: C/C++, Programming|Tags: , , , , , , , |

#include<stdio.h> int main() { int i,j,n,a,b; char s[100003]; scanf("%d%d%d",&n,&a,&b); scanf("%s",s); if(s[a-1]==s[b-1]) { printf("0"); } else printf("1"); return 0; }