标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 5134 Accepted Submission(s): 1288
1 #include <cstdio> 2 #include <queue> 3 #include <cstring> 4 #include <iostream> 5 #include <cstdlib> 6 #include <algorithm> 7 #include <vector> 8 #include <map> 9 #include <set> 10 #include <ctime> 11 #include <cmath> 12 #include <cctype> 13 #define MAX 100000 14 using namespace std; 15 int T,n,a[2],num[2],sum; 16 int main() 17 { 18 //freopen("/home/user/桌面/in","r",stdin); 19 scanf("%d",&T); 20 while(T--) 21 { 22 scanf("%d",&n); 23 if(n==1) 24 { 25 puts("0"); 26 continue; 27 } 28 sum=a[0]=a[1]=num[0]=num[1]=0; 29 if(n&1) a[1]=n,num[1]=1,a[0]=n-1,num[0]=0; 30 else a[0]=n,num[0]=1,a[1]=n+1,num[1]=0; 31 while(a[0]!=1) 32 { 33 //printf("%d %d %d %d\n",a[0],a[1],num[0],num[1]); 34 if(a[0]&1) sum+=num[0]; 35 if(a[1]&1) sum+=num[1]; 36 if(a[0]&1) 37 { 38 num[1]=(num[1]<<1)+num[0]; 39 } 40 else 41 { 42 num[0]=(num[0]<<1)+num[1]; 43 } 44 a[0]>>=1; 45 a[1]=a[0]+1; 46 } 47 printf("%d\n",sum); 48 } 49 //printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC); 50 return 0; 51 }
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6165 Accepted Submission(s): 1585
1 #include <cstdio> 2 #include <queue> 3 #include <cstring> 4 #include <iostream> 5 #include <cstdlib> 6 #include <algorithm> 7 #include <vector> 8 #include <map> 9 #include <set> 10 #include <ctime> 11 #include <cmath> 12 #include <cctype> 13 #define MAX 100000 14 using namespace std; 15 int n,a,b,c,x,sum,money; 16 int main() 17 { 18 //freopen("/home/user/桌面/in","r",stdin); 19 while(scanf("%d%d%d%d",&n,&a,&b,&c)==4) 20 { 21 sum=money=0; 22 while(n--) 23 { 24 scanf("%d",&x); 25 sum+=x; 26 if(sum>=a&&sum<b) 27 { 28 sum=0; 29 money+=2; 30 } 31 else if(sum>=b&&sum<c) 32 { 33 sum=0; 34 money+=3; 35 } 36 else if(sum>=c) 37 { 38 sum=0; 39 money+=4; 40 } 41 } 42 printf("%d\n",money); 43 } 44 //printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC); 45 return 0; 46 }
Total Submission(s): 1219 Accepted Submission(s): 369
Problem Description
1 #include <cstdio> 2 #include <queue> 3 #include <cstring> 4 #include <iostream> 5 #include <cstdlib> 6 #include <algorithm> 7 #include <vector> 8 #include <map> 9 #include <set> 10 #include <ctime> 11 #include <cmath> 12 #include <cctype> 13 #define MAX 100000 14 using namespace std; 15 int T,a[3],b[3]; 16 int cmp(int*a,int*b) 17 { 18 // printf("%d %d %d %d %d %d\n",a[0],a[1],a[2],b[0],b[1],b[2]); 19 int c[7],d[7]; 20 memset(c,0,sizeof(c)); 21 memset(d,0,sizeof(d)); 22 c[a[0]]++;c[a[1]]++;c[a[2]]++; 23 d[b[0]]++;d[b[1]]++;d[b[2]]++; 24 int m1=0,m2=0,i1,i2; 25 for(int i=1;i<=6;i++) m1=max(m1,c[i]); 26 for(int i=1;i<=6;i++) m2=max(m2,d[i]); 27 // printf("%d %d\n",m1,m2); 28 if(m1!=m2) return m1-m2; 29 for(i1=6;i1>0;i1--) if(c[i1]==m1) break; 30 for(i2=6;i2>0;i2--) if(d[i2]==m2) break; 31 // printf("%d %d\n",i1,i2); 32 if(i1!=i2||m1==3) return i1-i2; 33 c[i1]=d[i2]=0; 34 for(i1=6;i1>0;i1--) if(c[i1]) break; 35 for(i2=6;i2>0;i2--) if(d[i2]) break; 36 // printf("%d %d\n",i1,i2); 37 if(i1!=i2||m1==2) return i1-i2; 38 c[i1]=d[i2]=0; 39 for(i1=6;i1>0;i1--) if(c[i1]) break; 40 for(i2=6;i2>0;i2--) if(d[i2]) break; 41 // printf("%d %d\n",i1,i2); 42 return i1-i2; 43 } 44 int main() 45 { 46 //freopen("/home/user/桌面/in","r",stdin); 47 scanf("%d",&T); 48 while(T--) 49 { 50 scanf("%d%d%d",&a[0],&a[1],&a[2]); 51 scanf("%d%d%d",&b[0],&b[1],&b[2]); 52 if(cmp(a,b)>0) 53 { 54 printf("%.3lf\n",1.0); 55 continue; 56 } 57 int c,maxc=0,a1[3]; 58 for(int i=0;i<3;i++) 59 { 60 memcpy(a1,a,sizeof(a)); 61 c=0; 62 for(int j=1;j<=6;j++) 63 { 64 a1[i]=j; 65 if(cmp(a1,b)>0) c++; 66 } 67 // printf("%d\n",c); 68 maxc=max(c,maxc); 69 } 70 printf("%.3lf\n",maxc/6.0); 71 } 72 //printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC); 73 return 0; 74 }
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3655 Accepted Submission(s): 1228
Problem Description
1 #include <cstdio> 2 #include <queue> 3 #include <cstring> 4 #include <iostream> 5 #include <cstdlib> 6 #include <algorithm> 7 #include <vector> 8 #include <map> 9 #include <set> 10 #include <ctime> 11 #include <cmath> 12 #include <cctype> 13 #define MAX 11000 14 using namespace std; 15 int T,n,zfs[MAX+10],zn,notpri[MAX]; 16 void init() 17 { 18 memset(notpri,0,sizeof(notpri)); 19 zfs[0]=-MAX; 20 zn=1; 21 for(int i=2;i<=MAX;i++) 22 if(!notpri[i]) for(int j=i*i;j<=MAX;j+=i) notpri[j]=1; 23 for(int i=2;i<=MAX;i++) if(!notpri[i]) zfs[zn++]=i*i; 24 } 25 int main() 26 { 27 //freopen("/home/user/桌面/in","r",stdin); 28 init(); 29 scanf("%d",&T); 30 while(T--) 31 { 32 scanf("%d",&n); 33 int *a=lower_bound(zfs,zfs+zn,n); 34 printf("%d\n",*a-n>n-*(a-1)?*(a-1):*a); 35 } 36 //printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC); 37 return 0; 38 }
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1051 Accepted Submission(s): 512
1 #include <cstdio> 2 #include <queue> 3 #include <cstring> 4 #include <iostream> 5 #include <cstdlib> 6 #include <algorithm> 7 #include <vector> 8 #include <map> 9 #include <set> 10 #include <ctime> 11 #include <cmath> 12 #include <cctype> 13 #define MAX 100000 14 using namespace std; 15 long long d[4][21],c[21][4]; 16 int n; 17 long long A(int m,int n) 18 { 19 long long ans=1; 20 for(;n>0;n--,m--) ans*=m; 21 return ans; 22 } 23 long long C(int m,int n) 24 { 25 return A(m,n)/A(n,n); 26 } 27 void init() 28 { 29 memset(d,0,sizeof(d)); 30 for(int i=0;i<=20;i+=3) 31 { 32 d[3][i]=A(i,i)/A(i/3,i/3); 33 for(int j=0;j<i;j+=3) d[3][i]/=A(3,3); 34 // printf("%lld %lld %lld %lld\n",A(i,i),i/3*A(3,3),A(i/3,i/3),d[3][i]); 35 } 36 // for(int i=0;i<=20;i++) printf("%lld ",d[3][i]);printf("\n"); 37 for(int i=0;i<=20;i++) 38 { 39 long long t; 40 for(int j=0;j<=i;j+=2) 41 { 42 t=A(i,j)/A(j/2,j/2); 43 for(int k=0;k<j;k+=2) t/=A(2,2); 44 d[2][i]+=t*d[3][i-j]; 45 } 46 } 47 // for(int i=0;i<=20;i++) printf("%lld ",d[2][i]);printf("\n"); 48 for(int i=0;i<=20;i++) 49 { 50 long long t; 51 for(int j=i;j>=0;j--) 52 { 53 t=A(i,j)/A(j,j); 54 d[1][i]+=t*d[2][i-j]; 55 } 56 } 57 // for(int i=0;i<=20;i++) printf("%lld ",d[1][i]);printf("\n"); 58 } 59 int main() 60 { 61 //freopen("/home/user/桌面/in","r",stdin); 62 init(); 63 while(scanf("%d",&n)==1&&n) printf("%lld\n",d[1][n]); 64 //printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC); 65 return 0; 66 }
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1868 Accepted Submission(s): 379
1 #include <cstdio> 2 #include <queue> 3 #include <cstring> 4 #include <iostream> 5 #include <cstdlib> 6 #include <algorithm> 7 #include <vector> 8 #include <map> 9 #include <set> 10 #include <ctime> 11 #include <cmath> 12 #include <cctype> 13 #define MAX 0x7fffffff 14 using namespace std; 15 long long a[13][2000],a2[50000]; 16 int n,an[14]; 17 int main() 18 { 19 //freopen("/home/user/桌面/in","r",stdin); 20 a2[3]=6; 21 for(an[2]=4;a2[an[2]-1]<=MAX;an[2]++) a2[an[2]]=a2[an[2]-1]/(an[2]-2)*an[2]; 22 an[2]--; 23 // printf("%d %d\n",a2[an[2]],a[2][an[2]-1]); 24 //for(int i=3;i<100;i++) printf("%lld ",a2[i]);printf("\n"); 25 for(int i=3,j;i<=12;i++) 26 { 27 a[i][1]=1; 28 for(j=2;j<i+2;j++) a[i][j]=j*a[i][j-1]; 29 //printf("%d\n",(int)a[i][j-1]); 30 for(;a[i][j-1]<=MAX;j++) a[i][j]=a[i][j-1]/(j-i)*j; 31 an[i]=j-1; 32 // printf("%d %d\n",a[i][an[i]],a[i][an[i]-1]); 33 //printf("%d\n",an[i]); 34 //for(int k=i+1;k<an[i];k++) printf(" %lld",a[i][k]);printf("\n"); 35 } 36 while(scanf("%d",&n)==1) 37 { 38 if(n==1) 39 { 40 printf("0\n\n"); 41 continue; 42 } 43 if(n==0) 44 { 45 printf("1\n0\n"); 46 continue; 47 } 48 int find=0; 49 for(int i=12,j;i>2;i--) 50 { 51 for(j=i+1;j<an[i]&&n>=a[i][j];j++) 52 { 53 if(n%a[i][j]==0) 54 { 55 find=1; 56 break; 57 } 58 } 59 if(find) 60 { 61 printf("%d\n%d",i,j-i+1); 62 for(int k=j-i+2;k<=j;k++) printf("*%d",k); 63 printf("\n"); 64 break; 65 } 66 } 67 if(find) continue; 68 int i; 69 for(i=3;i<an[2]&&n>=a2[i];i++) 70 { 71 if(n%a2[i]==0) 72 { 73 find=1; 74 break; 75 } 76 } 77 if(find) 78 { 79 printf("2\n%d*%d\n",i-1,i); 80 continue; 81 } 82 int m=sqrt(n); 83 for(i=2;i<=m;i++) 84 if(n%i==0) 85 { 86 find=1;break; 87 } 88 printf("1\n%d\n",find?i:n); 89 } 90 //printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC); 91 return 0; 92 }
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2254 Accepted Submission(s): 581
1 #include <cstdio> 2 #include <queue> 3 #include <cstring> 4 #include <iostream> 5 #include <cstdlib> 6 #include <algorithm> 7 #include <vector> 8 #include <map> 9 #include <set> 10 #include <ctime> 11 #include <cmath> 12 #include <cctype> 13 #define MAX 1000000000 14 using namespace std; 15 int n,m,ss[1010],sum[1010];//n num of v,m num of edge 16 bool v[1010]; 17 set<int>fib; 18 void init() 19 { 20 fib.clear(); 21 int a0,a1,a2; 22 fib.insert(1); 23 a1=1;a2=2; 24 while(a2<=MAX) 25 { 26 fib.insert(a2); 27 a2=a1+a2; 28 a1=a2-a1; 29 } 30 } 31 int findset(int x) 32 { 33 return ss[x]!=x?ss[x]=findset(ss[x]):x; 34 } 35 int findset1(int x) 36 { 37 int stacks[1010],i=-1; 38 while(ss[x]!=x) 39 { 40 stacks[++i]=x; 41 x=ss[x]; 42 } 43 while(i>=0) 44 { 45 ss[stacks[i]]=x; 46 i--; 47 } 48 return x; 49 } 50 int main() 51 { 52 //freopen("/home/user/桌面/in","r",stdin); 53 init(); 54 //for(set<int>::iterator i=fib.begin();i!=fib.end();i++) printf("%d ",*i);printf("\n"); 55 while(scanf("%d%d",&n,&m)==2) 56 { 57 for(int i=1,a;i<=n;i++) 58 { 59 scanf("%d",&a); 60 fib.count(a)?v[i]=1:v[i]=0; 61 } 62 for(int i=1;i<=n;i++) ss[i]=i; 63 for(int a,b,i=0;i<m;i++) 64 { 65 scanf("%d%d",&a,&b); 66 int x,y; 67 x=findset(a);y=findset(b); 68 ss[x]=y; 69 } 70 memset(sum,0,sizeof(sum)); 71 int maxsum=-1; 72 for(int i=1;i<=n;i++) 73 { 74 int idx=findset(i); 75 sum[idx]+=v[i]; 76 } 77 for(int i=1;i<=n;i++) 78 maxsum=max(maxsum,sum[i]); 79 printf("%d\n",maxsum); 80 } 81 //printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC); 82 return 0; 83 }
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5362 Accepted Submission(s): 857
1 #include <cstdio> 2 #include <queue> 3 #include <cstring> 4 #include <iostream> 5 #include <cstdlib> 6 #include <algorithm> 7 #include <vector> 8 #include <map> 9 #include <set> 10 #include <ctime> 11 #include <cmath> 12 #include <cctype> 13 #define MAX 10000 14 using namespace std; 15 int T,n,m,k,costs[MAX+10],cost[MAX+10],costidx[MAX+10],idx[MAX+10],vis[MAX+10]; 16 bool com(int&a,int&b) 17 { 18 return cost[a]<cost[b]; 19 } 20 int main() 21 { 22 //freopen("/home/user/桌面/in","r",stdin); 23 scanf("%d",&T); 24 while(T--) 25 { 26 scanf("%d%d%d",&n,&m,&k); 27 memset(vis,0,sizeof(vis)); 28 for(int i=1;i<=n;i++) scanf("%d",&costs[i]); 29 for(int i=0;i<m;i++) 30 { 31 scanf("%d",&idx[i]); 32 vis[idx[i]]=1; 33 costidx[i]=costs[idx[i]]; 34 } 35 int j=0; 36 for(int i=1;i<=n;i++) if(!vis[i]) cost[j++]=costs[i]; 37 sort(costidx,costidx+m); 38 sort(cost,cost+j); 39 int i,sum=0; 40 for(i=0;i<m;i++) 41 { 42 sum+=costidx[i]; 43 if(sum>k) break; 44 } 45 if(i<m) 46 { 47 puts("-1"); 48 continue; 49 } 50 n=j; 51 for(int j=0;j<n;j++) 52 { 53 sum+=cost[j]; 54 if(sum>k) break; 55 i++; 56 } 57 printf("%d\n",i); 58 } 59 //printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC); 60 return 0; 61 }
标签:
原文地址:http://www.cnblogs.com/cdyboke/p/5057057.html