The solution can be found by observation that if one player finds the total number of ball that is equal (2^n -1) then the player is looser. i.e. we find for n=3 it is true, so, if n=3 1st player looses, for n=4 1st player wins n=5 1st player wins, for n=6 1st player wins, for n=7 1st player
Category: Ad Hoc
11716
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <string> using namespace std; int main() { int t,l,m; string str; cin>>t; getchar(); while(t–) { char gr[105][105]; getline(cin,str); l=str.size(); m=sqrt(l); if(m*m!=l) { cout<<"INVALID\n"; } else { int k=0; for(int i=0;i<m;i++) { for(int j=0;j<m;j++) { gr[i][j]=str[k]; k+=1; } } for(int i=0;i<m;i++) { for(int j=0;j<m;j++) cout<<gr[j][i]; } cout<<"\n";
10703
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #define INF 1000000 using namespace std; void swp(int *p,int *q) { int tmp; tmp=*p; *p=*q; *q=tmp; } int main() { int h,w,n; int a,b,c,d; bool gr[505][505]; while(cin>>h) { cin>>w>>n; if(h+w+n==0) break; memset(gr,0,sizeof(gr)); int cnt=0; for(int k=0;k<n;k++) { cin>>a>>b>>c>>d; if(a>c) swp(&a,&c); if(b>d) swp(&b,&d); for(int i=a;i<=c;i++) { for(int j=b;j<=d;j++)
496
Using set::set_intersect(params) the problem can be solved. #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <set> #include <algorithm> #include <sstream> #define INF 1000000 using namespace std; set<int> Set1,Set2,inn; int main() { int n; string str; stringstream ss; while(getline(cin,str)) { Set1.clear(); Set2.clear(); inn.clear(); ss.clear(); ss<<str; while(ss>>n) { Set1.insert(n); } getline(cin,str); ss.clear(); ss<<str; while(ss>>n) { Set2.insert(n);
10771
This is a very problem. Explanation: Elimination continues till there is a single maid remains. If number of keka maids are odd at beginning it never becomes even through the elimination process so it will reach at 1 first. And if the number of keka maids starts with even number it never becomes odd according
11565
#include <iostream> #include <cmath> #include <cstdio> #include <vector> #include <algorithm> using namespace std; vector<int> vb; int main() { int t; int A,B,C; cin>>t; while(t–) { cin>>A>>B>>C; bool found=0; vb.clear(); for(int i=-100;i<=100;i++) { for(int j=-100;j<=100;j++) { for(int k=-100;k<=100;k++) { if(i+j+k==A) if(i*j*k==B) if(i*i+j*j+k*k==C) if(i!=j && i!=k && j!=k) { vb.push_back(i);vb.push_back(j);vb.push_back(k); found=1; i=101;j=101;k=101; } } } } if(found)
10773
This one is also a shitty problem, had to try and error to get accepted, do not know why it got AC. #include <iostream> #include <cmath> #include <cstdio> const double eps = 1e-6; using namespace std; int main() { int t,kase=1; double d,v,u; double x; cin>>t; while(t–) { cin>>d>>v>>u; printf("Case %d: ", kase++); if(u-v<eps ||
11588
#include <iostream> #include <cstdio> #include <sstream> #include <string> #include <cstring> using namespace std; int arr[27]; int main() { int t,ans; int kase=1; char ch; int R,C,M,N; cin>>t; while(t–) { cin>>R>>C>>M>>N; memset(arr,0,sizeof(arr)); for(int i=0;i<R*C;i++) { cin>>ch; arr[ch-'A']+=1; } int mx=-1; for(int i=0;i<26;i++) { if(arr[i]>mx) mx=arr[i]; } int cnt=0; for(int i=0;i<26;i++) { if(arr[i]==mx) cnt+=1; } ans=mx*cnt*M+(R*C-mx*cnt)*N; cout<<"Case
11687
#include <iostream> #include <cstdio> #include <sstream> #include <string> using namespace std; int main() { int n,cnt; string s,t; stringstream ss; while(cin>>s) { if(s=="END") break; n=s.size(); cnt=1; ss.clear(); ss<<n; ss>>t; while(s!=t) { s=t; n=s.size(); ss.clear(); ss<<n; ss>>t; cnt+=1; } cout<<cnt<<"\n"; } return 0; }
11634
#include <iostream> #include <cstring> #include <string> using namespace std; bool trace[10000]; int random(int n) { int a=n*n; int arr[10]; int k=8; while(a) { arr[k]=a%10; k-=1; a/=10; } for(int i=k;i>=1;i–) arr[i]=0; int num=0; for(int i=3;i<=6;i++) { num*=10; num+=arr[i]; } return num; } int main() { int n,k; int cnt; while(cin>>n) { if(n==0) break; memset(trace,0,sizeof(trace)); cnt=1; int