//////2010 #include #include #include using namespace std; map<int,int>m; bool Prime[10007]; int P[10005],n; const int maxn=10000; int main() { n=0; memset(Prime,1,sizeof(Prime)); Prime[0]=Prime[1]=0; for(int i=2;i<=maxn;++i) { if(Prime[i]) { P[n++]=i; for(int j=2;j*i<=maxn;++j) { Prime[j*i]=0; } } } for(int i=0;P[i]!=0;i++) m[P[i]]=i; int n; while(cin>>n&&n) { int count=0; if(Prime[n]) count++; for(int i=2;i<=n;i++) { if(Prime[i]==0) continue; int sum=i; int j=P[m[i]+1]; while(Prime[j]!=0&&sum<=n) { sum+=j; if(sum==n) { count++; break; } j=P[m[j]+1]; } } cout<endl; } return 0; } /////3294 #include #include #include<string.h> int num[333333]; int set[333333]; int under[333333]; int find(int x) { int tmp; if (x!=set[x]) { tmp = find(set[x]); under[x] += under[set[x]]; set[x] = tmp; } return set[x]; } void merge(int a,int b) { int fx=find(a); int fy=find(b); if(fx!=fy) { under[fx]=num[fy]; num[fy]+=num[fx]; set[fx]=fy; } } int main() { int n,a,b; char s[5]; while(scanf("%d",&n)!=EOF) { memset(under,0,sizeof(under)); for(int i=0; i<=n; i++)//初始化 { set[i]=i; num[i]=1; } for(int i=0; i) { scanf("%s",s); if(s[0]=='M') { scanf("%d%d",&a,&b); merge(a,b); } else { scanf("%d",&a); find(a); printf("%d\n",under[a]); } } } return 0; } /* 6 M 1 6 C 1 M 2 4 M 2 6 C 3 C 4 */ /////3484 #include #include using namespace std; int s[100000]; int main () { int y; cin>>y; while(y--) { int a; cin>>a; for(int i=0;i) cin>>s[i]; sort(s,s+a); int asd=0; for(int i=0;i1;i++) { asd+=s[i]; } cout<endl; } //system("pause"); return 0; } ////3579 #include using namespace std; int pfac[6000]; int qfac[6000]; int ptable( int p ) { int j = 0; for( int i = 1; i <= p; i++ ) if( p % i == 0 ) pfac[j++] = i; return j; } int qtable( int q ) { int j = 0; for( int i = 1; i <= q; i++ ) if( q % i == 0 ) qfac[j++] = i; return j; } int main() { int p, q; cin >> p >> q; int psize, qsize; psize = ptable(p); qsize = qtable(q); int i, j; for( i = 0; i < psize; i++ ) for( j = 0; j < qsize; j++ ) cout << pfac[i] << " " << qfac[j] << endl; return 0; } ////////3861 #include using namespace std; int main(){ int n; while(cin>>n) {cout<<"Ann wins."<<endl;} } //////4088 #include #include #include using namespace std; bool isPrime(int num) { if(num<=1) return 0; for (int i=2; i<=sqrt(num); i++) { if (num%i == 0) return false; } return true; } int main() { int a,b; while(scanf("%d%d",&a,&b)!=EOF) { int counter = 0; for (int i=a; i<=b; i++) { if (isPrime(i)) { counter++; } } if(isPrime(counter)) { printf("YES"); printf("\n"); } else { printf("NO"); printf("\n"); } } //system("pause"); return 0; } ////////4116 #include using namespace std; int cnm(int a,int b) { if(a<b) swap(a,b); while(b) { a=a%b; swap(a,b); } return a; } int main() { int a; cin>>a; while(a--) { int n,sum; cin>>n>>sum; for(int i=1;i) { int x; cin>>x; sum=cnm(sum,x); } cout<endl; } // system("pause"); return 0; } //////////3170 #include using namespace std; int main () { int n,q,num,s[20000]; while(cin>>n>>q) { int b=0; for(int j=1;j<=n;j++) { int a; cin>>a; for(int i=b;i) s[i]=j; b+=a; } for(int i=1;i<=q;i++) { cin>>num; cout<endl; } } //system("pause"); return 0; } ///////1730 #include #include using namespace std; int main () { int s[20000]={0}; for(int i=1;i<=10000;i++) { int a=i,b=i; while(b) { a+=b%10; b=b/10; } s[a]=1; } for(int i=1;i<=10000;i++) { if(s[i]==0) cout<endl; } //system("pause"); return 0; } //////2218 #include using namespace std; int cnm(int a,int b,int c) { int sum=1,k=a; while(b) { if(b&1) sum=sum*k%c; k=k*k%c; b>>=1; } return sum; } int main() { int a; while(cin>>a&&a!=0) { cout<2006,a,2006)<<endl; } //system("pause"); return 0; } //////2218 #include using namespace std; int cnm(int a,int b,int c) { int sum=1,k=a; while(b) { if(b&1) sum=sum*k%c; k=k*k%c; b>>=1; } return sum; } int main() { int a; while(cin>>a&&a!=0) { cout<2006,a,2006)<<endl; } //system("pause"); return 0; } ///////////2916 -------------------------------------------------------------------------------- #include using namespace std; int cnm(int a,int b) { if(a<b) swap(a,b); while(b) { a=a%b; swap(a,b); } return a; } int main () { int x,y; while(cin>>x>>y) { int n; n=cnm(x,y); cout<endl; } //system("pause"); return 0; } //int cnm(int a,int b) //{ //if(a//swap(a,b); // while(b) //{ // a=a%b; // swap(a,b); //} //return a; //} //////4118 #include #include using namespace std; int main () { int a[1000001]; int n; while(cin>>n) { int j=0; memset(a,1,sizeof(a)); for(int i=n;i>0;i--) { if(a[i]&&i%2==0&&i>2) a[(i-2)/2]=0; } for(int i=1;i<=n;i++) if(a[i]) j++; cout<endl; } //system("pause"); return 0; } ////3855 #include #include using namespace std; int main () { int n,m; string menu[101]; double price[101]; while(cin>>n>>m) { double z=0.0; for(int i=0;i) cin>>menu[i]>>price[i]; for(int j=0;j) { string d; cin>>d; for(int i=0;i) { if(d==menu[i]) { z+=price[i]; price[i]=0; break; } } } cout<<fixed<2)<endl; } //system("pause"); return 0; } //////3161 #include using namespace std; int main () { int m,n,a[1000]; cin>>m>>n; for(int i=1;i<=m;i++) cin>>a[i]; while(n--) { int sum=0; int x,y; cin>>x>>y; for(x;x<=y;x++) sum+=a[x]; cout<endl; } //system("pause"); return 0; } /////////4102 #include #include using namespace std; int main () { int u,n; cin>>u; while(u--) { cin>>n; for(int i=0;;i++) { if(pow(2.0,i)>=n) {cout<break;} } } //system("pause"); return 0; } //////4101 #include using namespace std; int main () { int u; cin>>u; while (u--) { int a=0,s=1,n; cin>>n; while (a<n) { a+=s; if (a<n) s++; } cout<endl; } //system("pause"); return 0; } ////1192 #include #include using namespace std; int main () { int u; cin>>u; int a[10000],s[10000]; while (u) { int x=0,y=0; for (int i=1;i<=u;i++) cin>>a[i]; for (int j=1;j<=u;j++) cin>>s[j]; for (int i=1;i<=u;i++) { if (a[i]>s[i]) { if (a[i]==2&&s[i]==1) y+=6; else if(a[i]-s[i]==1) y+=a[i]+s[i]; else x+=a[i]; } else if (a[i]<s[i]) { if (a[i]==1&&s[i]==2) x+=6; else if (s[i]-a[i]==1) x+=a[i]+s[i]; else y+=s[i]; } } cout<<"A has "<" points. B has "<" points."<<endl; cin>>u; if (u!=0) cout<<endl; } //system ("pause"); //return 0; } /////////4109 #include using namespace std; int main () { int u; while (cin>>u&&u) { int a[u]; int w=0,s=0; for (int i=0;i) { cin>>a[i]; if (a[i]%2!=0) w++; else s++; } if (w>s&&u%2!=0) cout<<"Justice will prevail over evil."<<endl; else if(w2==0) cout<<"While the priest climbs a post, the devil climbs ten."<<endl; else cout<<"I love this world."<<endl; } //system("pause"); return 0; } /////////1680 #include int main() { int n,m,num; scanf("%d",&n); while (n--) { scanf("%d",&m); if(m%2==0) { m/=2; num=m*(m-1); } else { num=(m/2)*(m/2-1)/2+(m/2+1)*(m/2)/2; } printf("%d\n",num); } return 0; } /////////3105 #include using namespace std; int arr[100001]; int prime[100001]; int main(){ for(int i=2;i<=100000;i++) arr[i]=1; for(int i=2;i<=100000;i++){ if(arr[i]){ for(int j=i+i;j<=100000;j+=i) arr[j]=0; } } for(int i=2,j=1;i<=100000;i++){ if(arr[i]){ prime[j]=i; j++; } } int n;cin>>n; while(n--){ int m; cin>>m; cout<endl; } } ///////2791 #include using namespace std; int main(){ int n; cin>>n; while(n--){ string s; cin>>s; int l=s.length(); if(s[0]=='a'||s[0]=='e'||s[0]=='i'||s[0]=='o'||s[0]=='u') cout<"cow"<<endl; else{ for(int i=1;i) cout<<s[i]; cout<0]<<"ow"<<endl; } } } ////////3467 #include using namespace std; int main(){ int n;cin>>n; while(n--){ long long a,sun=0; cin>>a; while(a){ sun+=a%10; a/=10; } cout<endl; } } ///////////1457 #include using namespace std; int main () { int u; cin>>u; while(u--) { int s,d; cin>>s>>d; if(s2!=0) { cout<<"impossible"<<endl; } else cout<<(s+d)/2<<" "<<(s-d)/2<<endl; } return 0; } ///////3914 #include #include using namespace std; int main(){ int n; while(cin>>n){ int sun=0; while(n){ sun+=n%2; n/=2; } cout<2,sun)<<endl; } } ////////3982 #include #include #include using namespace std; int main () { int u; cin>>u; while (u--) { int t,y; cin>>t>>y; int a[y]; for (int i=0;i) { cin>>a[i]; } sort(a,a+y); int s=0,d=0; for (int i=0;i) { s+=a[i]; if (t>=s) d++; } cout<endl; } return 0; } /////////3108 #include #include using namespace std; int main(){ int n; cin>>n; while(n--){ int m1[10001],m2[10001],m3[10001],m4[10001],a,b,c=0; cin>>a>>b; for(int i=0;i) cin>>m1[i]; for(int i=0;i) cin>>m2[i]; for(int i=0;i){ for(int j=0;j){ if(m1[i]==m2[j]){ m3[c]=m1[i]; c++; break; } } } sort(m3,m3+c); m4[0]=m3[0]; int j=1; for(int i=1;i){ if(m3[i]!=m3[i-1]){ m4[j]=m3[i]; j++; } } for(int i=0;i1;i++) cout<" "; cout<1]<<endl; } } /////////////2955 #include using namespace std; int main () { int a[3],b[3]; while (cin>>a[0]>>b[0]>>a[1]>>b[1]>>a[2]>>b[2]) { int m,n; for(int i=0;i<=2;i++){ int x=0,y=0; for(int j=0;j<=2;j++){ if(a[i]!=a[j]) x++; if(b[i]!=b[j]) y++; } if(x==2) m=a[i]; if(y==2) n=b[i]; } cout<" "<endl; } return 0; } ///////3307 #include #include using namespace std; int m(int a,int b[],int r) { for (int i=0;i) if (a==b[i]) return i+1; return -1; } int main () { int row ,t,s[120],d[120]; while (cin>>row>>t) { int i,allow[120],allow1[120]; for (i=0;i) { cin>>s[i]>>d[i]; allow[i]=s[i]-d[i]; allow1[i]=allow[i]; } sort (allow ,allow+row); if (allow[0]<10) cout<<"The zombies eat your brains!" << endl; else { for (i=1;i) if (allow[i]-allow[i-1]<10) { cout << "The zombies eat your brains!" << endl; break; } if (i==row) { for (int j=0;j) { if (j!=0) cout<<" "; cout<<m(allow[j],allow1,row); } cout<<endl; } } } //system ("pause"); return 0; } /////1626 #include using namespace std; int x[25][25][25]={0}; int w(int a,int b,int c) { if (a<=0||b<=0||c<=0) return 1; if (a>20||b>20||c>20) return w(20,20,20); if (x[a][b][c]) { return x[a][b][c]; } if (ac) { x[a][b][c]=w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c); return x[a][b][c]; } else { x[a][b][c]=w(a-1,b,c)+w(a-1,b-1,c)+w(a-1,b,c-1)-w(a-1,b-1,c-1); return x[a][b][c]; } } int main () { int a,b,c; while (cin>>a>>b>>c&&(a!=-1||b!=-1||c!=-1)) { cout<<"w("<", "<", "<") = "<endl; } //system ("pause"); return 0; } ////////1574 #include #include using namespace std; int main () { double a[12],eve,sum=0; for (int i=0;i<12;i++) { cin>>a[i]; sum+=a[i]; } cout<<"$"<2)<<fixed<12<<endl; //system ("pause"); return 0; } /////////3469 #include using namespace std; int s(int a,int b) { int m=a,n=b,c; if (a<b) { int temp=a; a=b; b=temp; } while (b) { c=a%b; a=b; b=c; } return a; } int main () { int t; cin>>t; while (t--) { int m,n,b1,b2; cin>>m>>n>>b1>>b2; cout<endl; } //system ("pause"); return 0; } ///////3488 #include #include using namespace std; int main(){ int n,t; cin>>n; while(n--){ cin>>t; int sun=0; int a[100500]; for(int i=0;i){ cin>>a[i]; } sort(a,a+t); for(int i=0;i1;i++){ a[i+1]+=a[i]; sun+=a[i+1]; for(int j=i+1;j1;j++){ if(a[j]>a[j+1]) swap(a[j],a[j+1]); else break; } } cout<endl; } } ///////////////2859 #include #include using namespace std; int main(){ int n; while(cin>>n&&n){ int a[1000]; for(int i=0;i){ cin>>a[i]; } sort(a,a+n); for(int i=n-2;i>=0;i--){ if(a[i]1]){ cout<endl; break;} } } } /////1528 #include using namespace std; long long lcm(long long m, long long n){ long long a = m, b = n; if(a < b) swap(a, b); while(b != 0){ a = a % b; swap(a ,b); } return m * n / a; } int main() { int x; cin>>x; while(x--){ int y,m,n; cin>>y; cin>>m; for(int i=1;i<=y-1;i++){ cin>>n; m=lcm(m,n); } cout<endl; } } ///////////3224 #include using namespace std; int main() { int n;cin>>n; while(n--){ long long a,b; cin>>a>>b; cout<1<<endl; } } ////3470 #include #include using namespace std; int main(){ int t;cin>>t; while(t--){ int n;cin>>n; for(int i=0;;i++){ if(pow(2,i)>=n){ cout<endl; break; } } } } ////////3319 #include using namespace std; int gcd(int a,int b){ if(a<b) swap(a,b); while(b){ a=a%b; swap(a,b); } return a; } int main(){ int n,m,z; while(cin>>n>>m&&(m||n)){ m=m+1;n=n+2; z=gcd(m,n); cout<" "<endl; } } //////3150 #include using namespace std; int main() { int u; cin>>u; int o=0; while (u--) { int m,n,min,max; cin>>m>>n; { if(m>=n) { min=n; }else { min=m; } while(true){ if(m%min==0&&n%min==0){ break; } min--; } } { if(m>=n) { max=m; } else { max=n; } while(true){ if(max%m==0&&max%n==0){ break; } max++; } } o++; cout<" "<" "<endl; } } ////3237 #include<string> #include using namespace std; int main() { int T,B,L,R; string s; cin>>T; while(T--) { R=0; cin>>B>>s; for(int i=0;ii) { R=(R*B+s[i]-48)%10007; } cout<endl; } return 0; } ////3205 #include #include using namespace std; int main () { int n,a[100],b[100],x,c; while (cin>>n) { x=n; c=0; while (n--) { for (int i=0;i) { cin>>a[i]; } sort (a,a+x); b[c]=a[(x-1)/2]; c++; } sort (b,b+x); cout<1)/2]<<endl; } } ////////2891 #include using namespace std; int main(){ int n,T,a[21]; cin>>T; while(T--){ cin>>n; for(int i=0;i) cin>>a[i]; //i=0; while(n>0){ for(int i=0;i1;i++){ a[i]=a[i+1]-a[i]; } n--; } cout<0]<<endl; } return 0; } ///////////////1065 #include using namespace std; int main() { int num,key; cin>>key; while(key--) { cin>>num; int sum=0; int temp=5; while(num/temp!=0) { sum=sum+num/temp; temp=temp*5; } cout<endl; } return 0; } /////3471 #include using namespace std; int main() { int a; while (cin>>a&&a!=0) { if (a%3==0) cout<<"Unhappy"<<endl; else cout<<"Happy"<<endl; } return 0; } ////////2526 #include #include using namespace std; int main() { int b,n,a,x,y; while(cin>>b>>n&&b!=0&&n!=0){ for(int i=1;i<=1000000;i++){ x=pow(i,n); if(x>b){ y=pow(i-1,n); if(x-b>b-y) { cout<1<<endl; break; } else { cout<endl; break; } } else if(x==b){ cout<endl; break; } } } } ///////1412 #include #include using namespace std; int main () { int n; cin>>n; while (n--) { int x; cin>>x; int a[x]; int sum=0,h=0; double s,r; for (int i=0;i) { cin>>a[i]; sum+=a[i]; } s=sum/(1.0*x); for (int i=0;i) { if (a[i]>s) h++; } r=h/(1.0*x)*100; printf("%.3f%%\n",r); } return 0; } /////3496 #include #include using namespace std; int a (int s) { int t = 0; while (s > 0) { t = 10 * t + s % 10; s = s / 10; } return t; } int main () { int x; scanf("%d",&x); while (x--) { int y,u,i,o,p; scanf("%d%d",&y,&u); i=a(y); o=a(u); p=i+o; cout<endl; cout<<endl; } return 0; } ////////3059 #include using namespace std; int main () { int x; cin>>x; while (x--) { int c; int d=0; int f=0; cin>>c; char a[c],s[c]; for (int i=0;i) { cin>>a[i]>>s[i]; if(a[i]==s[i]); else if (a[i]=='P'&&s[i]=='R') d++; else if (a[i]=='P'&&s[i]=='S') f++; else if (a[i]=='R'&&s[i]=='S') d++; else if (a[i]=='R'&&s[i]=='P') f++; else if (a[i]=='S'&&s[i]=='P') d++; else if (a[i]=='S'&&s[i]=='R') f++; } if (d==f) cout<<"TIE"<<endl; else if (d>f) cout<<"Player 1"<<endl; else if (d<f) cout<<"Player 2"<<endl; } return 0; } ////////2891 #include using namespace std; int main() { int x; cin>>x; while (x--) { int s,a[25]; cin>>s; for (int i=0;i) cin>>a[i]; while (s--) { for (int i=0;i) a[i]=a[i+1]-a[i]; } cout<0]<<endl; } //system ("pause"); return 0; } //2803 #include #include #include #include #include #include using namespace std; int main () { int a; cin>>a; while (a--) { double a,b,c,v,x1,x2; cin>>a>>b>>c; if ((b*b-4*a*c)>=0) { v=sqrt(b*b-4*a*c); x1=(-b+v)/(2*a); x2=(-b-v)/(2*a); if (x1==x2) cout<fixed)<3)<endl; else cout<fixed)<3)<" "<endl; } else cout<<"No solution!"<<endl; } //system ("pause"); return 0; } ////2001 #include #include #include #include #include #include using namespace std; int main () { int t,n; string s[11]; cin >> t; for(int k = 1;k <= t;k++) { int ans = 0; cin >> n; for(int i = 0;i < n;i++) { cin >> s[i]; if(s[i] == "sheep") ans++; } printf("Case %d: This list contains %d sheep.\n",k,ans); if(k != t) cout << endl; } return 0; } /////2056 #include using namespace std; int f[10]; int A,B,C; void init() { C=f[0]; A=(f[2]-2*f[1]+f[0])/2; B=2*f[1]-1.5*f[0]-0.5*f[2]; } void count() { f[3]=A*3*3+B*3+C; f[4]=A*4*4+B*4+C; f[5]=A*5*5+B*5+C; } int main() { // freopen("fjnu_1707.in","r",stdin); while(cin>>f[0]>>f[1]>>f[2]) { init(); count(); cout<3]<<" "<4]<<" "<5]<<endl; } return 0; } //////1823 #include #include using namespace std; void c(int n){ if(n==0) cout<<"-"; else{ c(n-1); for(int i=0;i3,n-1);i++){ cout<<" "; } c(n-1); } } int main(){ int n; while(cin>>n){ c(n); cout<<endl; } return 0; } //////1279 #include #include using namespace std; bool complare(int a,int b) { return a>b; } int main () { int m; cin>>m; while (m--) { int x; cin>>x; int a[x]; int s[x]; for (int i=0;i) { cin >>a[i]; } sort (a,a+x,complare); for (int i=0;i) { s[i]=a[i]*(i+1); } sort (s,s+x,complare); cout<0]<<endl; } //system("pause"); return 0; } ////////1089 #include using namespace std; int happy(int n) { int r,f,t,d; f=t=d=1; for (r=0;r<=n;++r) { f=f*(r==n?2:4)%29; t=t*3%29; d=d*22%29; } r=(f-1)*(t-1)*(d-1)%29; return r*9%29; } int main() { int n; while (cin>>n && n!=0) { cout<28)<<endl; } return 0; } /////1331 #include int p, q, r, s, i; double ans; int main () { while (~scanf("%d%d%d%d", &p, &q, &r, &s)) { ans = 1.0; if (p - q < q) q = p - q; if (r - s < s) s = r - s; for (i = 1; i <= q || i <= s; i ++) { if (i <= q) { ans = ans * (p - q + i) / i; } if (i <= s) { ans = ans / (r - s + i) * i; } } printf("%.5lf\n", ans); } return 0; } //////1015 #include #include #include #include using namespace std; int main () { int n; cin>>n; for (int i=1;i<=n;i++) { int x,y; cin>>x>>y; double k; if (x%2==0||y%2==0) { k=double (x*y); cout<<fixed<2)<<"Scenario #"<":\n"<endl; } else { k=x*y+0.41; cout<<fixed<2)<<"Scenario #"<":\n"<endl; } cout<<endl; } //system("pause"); return 0; } ///////1601 #include #include #include #include using namespace std; int main() { int m; int h=1; while (cin>>m&&m) { int n=0; int a[1000]; int sum=0; for (int i=0;i) { cin>>a[i]; sum+=a[i]; } //cout< sum=sum/m; //cout< int s; for (int j=0;j) { s=a[j]-sum; if (s>0) n+=s; } //cout< cout<<"Set #"<endl; cout<<"The minimum number of moves is "<"."<<endl; h++; cout<<endl; } return 0; } //////3843 #include #include #include #include using namespace std; int main () { int a,b; cin>>a>>b; int s[4010]; int d[160010]; int y=0; for (int i=0;i) { cin>>s[i]; } sort(s,s+a); for (int j=0;j) { cin>>d[j]; } sort(d,d+b); int u=0; int o=0; while(ub) { if (s[u]<d[o]) u++; if (s[u]>d[o]) o++; if(s[u]==d[o]) { u++; o++; y++; } } cout<endl; return 0; } ////1805 #include #include #include using namespace std; int main () { int m,a; cin>>m; int s[100]; while (m--) { int d=0;; cin>>a; for(int i=0;i) { cin>>s[i]; d+=s[i]; } d+=-a+1; cout<endl; } return 0; } ////////2538 #include #include #include #include using namespace std; int h(int n) { int y=0; for (int i=1;i<=n;i++) { y+=i; } //cout< return y; } int main () { int u; cin>>u; int a[u]; int t=0; while (u--) { int m; cin>>m; int sum=0; for (int o=1;o<=m;o++) { int p=h(o+1); //cout< sum=sum+o*p; //cout< } a[t]=sum; cout<1<<" "<" "<endl; t++; } return 0; } ////////3503 #include #include #include #include #include using namespace std; int main () { int m; cin>>m; int a[10001]; int g[10001]; while (m--) { int u; cin>>u; memset(g,0,sizeof(g)); for (int i=1;i<=u;i++) { cin>>a[i]; for (int j=1;j<=i;j++) if (a[i]==a[j]) g[i]++; } sort(g,g+10001); cout <10000]<<endl; } return 0; } ///////2800 #include #include #include using namespace std; int main () { int m,n,z,x; cin>>m; while (m--) { cin>>n; z=n*n-n+1; x=n*n+n-1; cout<" "<endl; } return 0; } /////////2994 #include #include #include using namespace std; int main () { int m; cin>>m; for (int r=0;r) { int b; int a[10]; int z[10]; cin>>b; int n=0; for (int i=0;i) { cin>>a[i]; } for (int o=0;o) { cin>>
endl; cout<<endl; } return 0; } ////////3059 #include using namespace std; int main () { int x; cin>>x; while (x--) { int c; int d=0; int f=0; cin>>c; char a[c],s[c]; for (int i=0;i) { cin>>a[i]>>s[i]; if(a[i]==s[i]); else if (a[i]=='P'&&s[i]=='R') d++; else if (a[i]=='P'&&s[i]=='S') f++; else if (a[i]=='R'&&s[i]=='S') d++; else if (a[i]=='R'&&s[i]=='P') f++; else if (a[i]=='S'&&s[i]=='P') d++; else if (a[i]=='S'&&s[i]=='R') f++; } if (d==f) cout<<"TIE"<<endl; else if (d>f) cout<<"Player 1"<<endl; else if (d<f) cout<<"Player 2"<<endl; } return 0; } ////////2891 #include using namespace std; int main() { int x; cin>>x; while (x--) { int s,a[25]; cin>>s; for (int i=0;i) cin>>a[i]; while (s--) { for (int i=0;i) a[i]=a[i+1]-a[i]; } cout<0]<<endl; } //system ("pause"); return 0; } //2803 #include #include #include #include #include #include using namespace std; int main () { int a; cin>>a; while (a--) { double a,b,c,v,x1,x2; cin>>a>>b>>c; if ((b*b-4*a*c)>=0) { v=sqrt(b*b-4*a*c); x1=(-b+v)/(2*a); x2=(-b-v)/(2*a); if (x1==x2) cout<fixed)<3)<endl; else cout<fixed)<3)<" "<endl; } else cout<<"No solution!"<<endl; } //system ("pause"); return 0; } ////2001 #include #include #include #include #include #include using namespace std; int main () { int t,n; string s[11]; cin >> t; for(int k = 1;k <= t;k++) { int ans = 0; cin >> n; for(int i = 0;i < n;i++) { cin >> s[i]; if(s[i] == "sheep") ans++; } printf("Case %d: This list contains %d sheep.\n",k,ans); if(k != t) cout << endl; } return 0; } /////2056 #include using namespace std; int f[10]; int A,B,C; void init() { C=f[0]; A=(f[2]-2*f[1]+f[0])/2; B=2*f[1]-1.5*f[0]-0.5*f[2]; } void count() { f[3]=A*3*3+B*3+C; f[4]=A*4*4+B*4+C; f[5]=A*5*5+B*5+C; } int main() { // freopen("fjnu_1707.in","r",stdin); while(cin>>f[0]>>f[1]>>f[2]) { init(); count(); cout<3]<<" "<4]<<" "<5]<<endl; } return 0; } //////1823 #include #include using namespace std; void c(int n){ if(n==0) cout<<"-"; else{ c(n-1); for(int i=0;i3,n-1);i++){ cout<<" "; } c(n-1); } } int main(){ int n; while(cin>>n){ c(n); cout<<endl; } return 0; } //////1279 #include #include using namespace std; bool complare(int a,int b) { return a>b; } int main () { int m; cin>>m; while (m--) { int x; cin>>x; int a[x]; int s[x]; for (int i=0;i) { cin >>a[i]; } sort (a,a+x,complare); for (int i=0;i) { s[i]=a[i]*(i+1); } sort (s,s+x,complare); cout<0]<<endl; } //system("pause"); return 0; } ////////1089 #include using namespace std; int happy(int n) { int r,f,t,d; f=t=d=1; for (r=0;r<=n;++r) { f=f*(r==n?2:4)%29; t=t*3%29; d=d*22%29; } r=(f-1)*(t-1)*(d-1)%29; return r*9%29; } int main() { int n; while (cin>>n && n!=0) { cout<28)<<endl; } return 0; } /////1331 #include int p, q, r, s, i; double ans; int main () { while (~scanf("%d%d%d%d", &p, &q, &r, &s)) { ans = 1.0; if (p - q < q) q = p - q; if (r - s < s) s = r - s; for (i = 1; i <= q || i <= s; i ++) { if (i <= q) { ans = ans * (p - q + i) / i; } if (i <= s) { ans = ans / (r - s + i) * i; } } printf("%.5lf\n", ans); } return 0; } //////1015 #include #include #include #include using namespace std; int main () { int n; cin>>n; for (int i=1;i<=n;i++) { int x,y; cin>>x>>y; double k; if (x%2==0||y%2==0) { k=double (x*y); cout<<fixed<2)<<"Scenario #"<":\n"<endl; } else { k=x*y+0.41; cout<<fixed<2)<<"Scenario #"<":\n"<endl; } cout<<endl; } //system("pause"); return 0; } ///////1601 #include #include #include #include using namespace std; int main() { int m; int h=1; while (cin>>m&&m) { int n=0; int a[1000]; int sum=0; for (int i=0;i) { cin>>a[i]; sum+=a[i]; } //cout< sum=sum/m; //cout< int s; for (int j=0;j) { s=a[j]-sum; if (s>0) n+=s; } //cout< cout<<"Set #"<endl; cout<<"The minimum number of moves is "<"."<<endl; h++; cout<<endl; } return 0; } //////3843 #include #include #include #include using namespace std; int main () { int a,b; cin>>a>>b; int s[4010]; int d[160010]; int y=0; for (int i=0;i) { cin>>s[i]; } sort(s,s+a); for (int j=0;j) { cin>>d[j]; } sort(d,d+b); int u=0; int o=0; while(ub) { if (s[u]<d[o]) u++; if (s[u]>d[o]) o++; if(s[u]==d[o]) { u++; o++; y++; } } cout<endl; return 0; } ////1805 #include #include #include using namespace std; int main () { int m,a; cin>>m; int s[100]; while (m--) { int d=0;; cin>>a; for(int i=0;i) { cin>>s[i]; d+=s[i]; } d+=-a+1; cout<endl; } return 0; } ////////2538 #include #include #include #include using namespace std; int h(int n) { int y=0; for (int i=1;i<=n;i++) { y+=i; } //cout< return y; } int main () { int u; cin>>u; int a[u]; int t=0; while (u--) { int m; cin>>m; int sum=0; for (int o=1;o<=m;o++) { int p=h(o+1); //cout< sum=sum+o*p; //cout< } a[t]=sum; cout<1<<" "<" "<endl; t++; } return 0; } ////////3503 #include #include #include #include #include using namespace std; int main () { int m; cin>>m; int a[10001]; int g[10001]; while (m--) { int u; cin>>u; memset(g,0,sizeof(g)); for (int i=1;i<=u;i++) { cin>>a[i]; for (int j=1;j<=i;j++) if (a[i]==a[j]) g[i]++; } sort(g,g+10001); cout <10000]<<endl; } return 0; } ///////2800 #include #include #include using namespace std; int main () { int m,n,z,x; cin>>m; while (m--) { cin>>n; z=n*n-n+1; x=n*n+n-1; cout<" "<endl; } return 0; } /////////2994 #include #include #include using namespace std; int main () { int m; cin>>m; for (int r=0;r) { int b; int a[10]; int z[10]; cin>>b; int n=0; for (int i=0;i) { cin>>a[i]; } for (int o=0;o) { cin>>
sum=sum+o*p; //cout< } a[t]=sum; cout<1<<" "<"