通过这次比赛,让我意识到了学弟学妹们成长速度之快,作为学长,压力山大啊,真不知道再过一阵子,学长是不是要被虐了
对于这次的比赛题目,题目的难度本身没有多大(毕竟新生为主,但像我这样的渣渣老生也还是要去被虐虐的),基本都可以暴力求解,就看你想不想得到
2 4 5
0 2
暂且不管,因为递归过不了,所以后来改离线了,就是在询问前求解并记录所有的解,对于n,我们会分成n/2和n-n/2两堆,那我们只要先求解出n/2的状态和n-n/2的状态,就可以得到n的状态,其实和递归思路差不多,只是离线省去了重复计算的过程
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<stdio.h> #include<string.h> #include<stdlib.h> #include<queue> #include<stack> #include<math.h> #include<vector> #include<map> #include<set> #include<cmath> #include<string> #include<algorithm> #include<iostream> #define exp 1e-10 using namespace std; const int N = 10000005; const int M = 10005; const int inf = 1000000000; const int mod = 2009; int s[N]; int f_abs(int x) { if(x<0) return -x; return x; } int main() { int t,n,i; s[0]=s[1]=0; for(i=2;i<N;i++) s[i]=s[i/2]+s[i-i/2]+f_abs(i-i/2-i/2); scanf("%d",&t); while(t--) { scanf("%d",&n); printf("%d\n",s[n]); } return 0; }
3 2 4 6 2 2 1
4
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<stdio.h> #include<string.h> #include<stdlib.h> #include<queue> #include<stack> #include<math.h> #include<vector> #include<map> #include<set> #include<cmath> #include<string> #include<algorithm> #include<iostream> #define exp 1e-10 using namespace std; const int N = 10005; const int M = 10005; const int inf = 1000000000; const int mod = 2009; int main() { int n,a,b,c,t,i,x,ans; while(~scanf("%d%d%d%d",&n,&a,&b,&c)) { ans=t=0; for(i=0;i<n;i++) { scanf("%d",&x); t+=x; if(t>=a&&t<b) { ans+=2; t=0; } else if(t>=b&&t<c) { ans+=3; t=0; } else if(t>=c) { ans+=4; t=0; } } printf("%d\n",ans); } return 0; }
4 2 3 5 3 3 4 3 3 1 2 2 2 6 2 1 5 4 3 1 2 3 4 4 1
0.333 0.167 1.000 0.000
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<stdio.h> #include<string.h> #include<stdlib.h> #include<queue> #include<stack> #include<math.h> #include<vector> #include<map> #include<set> #include<cmath> #include<string> #include<algorithm> #include<iostream> #define exp 1e-10 using namespace std; const int N = 25; const int M = 1005; const int inf = 1000000007; const int mod = 2009; int fun(int a,int b,int c) { if(a==b&&b==c) return 3; else if(a==b||a==c||b==c) return 2; return 1; } int solve(int a,int b,int c,int d,int e,int f) { int k1=fun(a,b,c),k2=fun(d,e,f),x1,x2,y1,y2; if(k1>k2) return 3; else if(k1<k2) return 1; if(k1==3) { if(a>d) return 3; else if(a<d) return 1; else return 2; } else if(k1==2) { if(a==b) x1=a,x2=c; else if(a==c) x1=a,x2=b; else if(b==c) x1=b,x2=a; if(d==e) y1=d,y2=f; else if(d==f) y1=d,y2=e; else if(e==f) y1=e,y2=d; if(x1!=y1) { if(x1>y1) return 3; if(x1<y1) return 1; } if(x2>y2) return 3; else if(x2<y2) return 1; else return 2; } else if(k1==1) { if(a<b) swap(a,b); if(a<c) swap(a,c); if(b<c) swap(b,c); if(d<e) swap(d,e); if(d<f) swap(d,f); if(e<f) swap(e,f); if(a!=d) { if(a>d) return 3; else return 1; } if(b!=e) { if(b>e) return 3; else return 1; } if(c>f) return 3; else if(c<f) return 1; return 2; } } int main() { int t,a,b,c,d,e,f,ans,i; double sol; scanf("%d",&t); while(t--) { sol=0; scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f); if(solve(a,b,c,d,e,f)==3) { puts("1.000"); continue; } for(ans=0,i=1;i<=6;i++) if(solve(i,b,c,d,e,f)==3) ans++; sol=max(sol,ans*1.0/6); for(ans=0,i=1;i<=6;i++) if(solve(a,i,c,d,e,f)==3) ans++; sol=max(sol,ans*1.0/6); for(ans=0,i=1;i<=6;i++) if(solve(a,b,i,d,e,f)==3) ans++; sol=max(sol,ans*1.0/6); printf("%.3f\n",sol); } return 0; }
2 1 10
4 9
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<stdio.h> #include<string.h> #include<stdlib.h> #include<queue> #include<stack> #include<math.h> #include<vector> #include<map> #include<set> #include<cmath> #include<string> #include<algorithm> #include<iostream> #define exp 1e-10 using namespace std; const int N = 10005; const int M = 10005; const int inf = 1000000000; const int mod = 2009; int s[N],prime[N],k=1; bool v[N]; int f_abs(int x) { if(x<0) return -x; return x; } void get_prime() { memset(v,false,sizeof(v)); for(int i=2;i<N;i++) if(!v[i]) { prime[k++]=i*i; for(int j=i+i;j<N;j+=i) v[j]=true; } } int main() { int t,n,i,c; prime[0]=-inf; get_prime();//printf("%d",k); scanf("%d",&t); while(t--) { scanf("%d",&n); c=lower_bound(prime,prime+k,n)-prime; if(prime[c]-n>n-prime[c-1]) printf("%d\n",prime[c-1]); else printf("%d\n",prime[c]); } return 0; }
1 2 3 4 5 0
1 2 5 14 46
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<stdio.h> #include<string.h> #include<stdlib.h> #include<queue> #include<stack> #include<math.h> #include<vector> #include<map> #include<set> #include<cmath> #include<string> #include<algorithm> #include<iostream> #define exp 1e-10 using namespace std; const int N = 25; const int M = 1005; const int inf = 1000000007; const int mod = 2009; __int64 dp[N][N][N][N],c[N][N]; int main() { int i,j,k,l,n,x,y; __int64 sum; for(i=0;i<=20;i++) for(j=0;j<=i;j++) if(j==0||i==j) c[i][j]=1; else c[i][j]=c[i-1][j]+c[i-1][j-1]; for(i=1;i<=20;i++) for(l=0;l<=20;l++) for(k=0;k<=20;k++) { j=i-3*l-2*k; if(j<0||j==0&&k==0&&l==0) continue; dp[i][j][k][l]=1;y=i; for(x=1;x<=k;x++,y-=2) dp[i][j][k][l]*=c[y][2];//y个里面不断选2个,C(y,2) for(x=1;x<=k;x++) dp[i][j][k][l]/=x;//除掉相同个数的分组,k! for(x=1;x<=l;x++,y-=3) dp[i][j][k][l]*=c[y][3];//y个里面不断选3个,C(y,3) for(x=1;x<=l;x++) dp[i][j][k][l]/=x; //if(i<5) //printf("%d %d %d %d %I64d\n",i,j,k,l,dp[i][j][k][l]); } while(scanf("%d",&n)&&n) { sum=0; for(j=0;j<=20;j++) for(k=0;k<=20;k++) for(l=0;l<=20;l++) if(j+2*k+3*l==n) { //printf("%I64d\n",dp[n][j][k][l]); sum+=dp[n][j][k][l]; } printf("%I64d\n",sum); } return 0; }
630 12
3 5*6*7 2 2*3Hint630 = 3*5*6*7
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<stdio.h> #include<string.h> #include<stdlib.h> #include<queue> #include<stack> #include<math.h> #include<vector> #include<map> #include<set> #include<cmath> #include<string> #include<algorithm> #include<iostream> #define exp 1e-10 using namespace std; const int N = 100005; const int M = 10005; const int inf = 1000000000; const int mod = 10007; int main() { int n,k,i,x,t,Max,s,j; bool flag; while(~scanf("%d",&n)) { flag=false; if(n==0||n==1) { printf("1\n0\n"); continue; } k=(int)sqrt(n);x=n;t=0;Max=0; for(i=2;i<=k;i++) { if(x%i==0) { flag=true; for(j=i;x%j==0;j++) { x/=j; t++; } if(Max<t) Max=t,s=i; t=0,x=n; } } if(!flag) { printf("1\n%d\n",n); continue; } printf("%d\n",Max); for(i=s;i<s+Max;i++) printf("%d%c",i,i==s+Max-1?'\n':'*'); } return 0; }
2 1 1 4 1 2
1
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<stdio.h> #include<string.h> #include<stdlib.h> #include<queue> #include<stack> #include<math.h> #include<vector> #include<map> #include<set> #include<cmath> #include<string> #include<algorithm> #include<iostream> #define exp 1e-10 using namespace std; const int N = 1005; const int M = 1005; const int inf = 1000000007; const int mod = 2009; int s[N],a[N],c[N],ans[N]; int fun(int x) { if(c[x]!=x) c[x]=fun(c[x]); return c[x]; } int main() { int i,n,m,u,v,k,x,Max,p; s[0]=1;s[1]=1; for(i=2;;i++) { s[i]=s[i-1]+s[i-2]; if(s[i]>1000000000) break; }p=i; while(~scanf("%d%d",&n,&m)) { memset(ans,0,sizeof(ans)); for(i=1;i<=n;i++) c[i]=i; for(i=1;i<=n;i++) scanf("%d",&a[i]); for(i=0;i<m;i++) { scanf("%d%d",&u,&v); c[fun(u)]=fun(v); } for(i=1;i<=n;i++) { k=fun(i); x=lower_bound(s,s+p,a[i])-s; if(s[x]==a[i]) ans[k]++; } for(Max=0,i=1;i<=n;i++) Max=max(Max,ans[i]); printf("%d\n",Max); } return 0; }
2 5 2 10 4 3 8 1 12 1 2 5 2 10 4 3 8 1 12 1 3
3 -1
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<stdio.h> #include<string.h> #include<stdlib.h> #include<queue> #include<stack> #include<math.h> #include<vector> #include<map> #include<set> #include<cmath> #include<string> #include<algorithm> #include<iostream> #define exp 1e-10 using namespace std; const int N = 10005; const int M = 10005; const int inf = 1000000007; const int mod = 2009; int s[N]; int main() { int t,n,m,k,i,x,ans; bool flag; scanf("%d",&t); while(t--) { flag=true;ans=0; scanf("%d%d%d",&n,&m,&k); for(i=1;i<=n;i++) scanf("%d",&s[i]); for(i=0;i<m;i++) { scanf("%d",&x); k-=s[x];ans++; if(k<0) flag=false; s[x]=inf; } if(!flag) { puts("-1"); continue; } sort(s+1,s+1+n); for(i=1;i<=n;i++) if(k>=s[i]) { ans++; k-=s[i]; } else break; printf("%d\n",ans); } return 0; }