The 10th Zhejiang Provincial Collegiate Programming Contest
Applications http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5008
string set 专场
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #include<iostream> 5 #include<algorithm> 6 #include<set> 7 #define mt(a,b) memset(a,b,sizeof(a)) 8 using namespace std; 9 const double eps=1e-8; 10 const int M=10000; 11 set<int> A,B; 12 set<string> xiaosai[4]; 13 int defen[]={0,36,27,18}; 14 char op[32]; 15 struct G{ 16 double val; 17 string name; 18 friend bool operator <(const G &a,const G &b){ 19 return a.val>b.val||(fabs(a.val-b.val)<eps&&a.name<b.name); 20 } 21 }p[512]; 22 int pri[M],mark[M],pricnt;//mark[i]存i的最小因子,素数时mark[i]==i 23 void sieve_primes() { //筛素数 24 pricnt=0; 25 mt(mark,0); 26 mark[0]=mark[1]=1; 27 for(int i=2; i<M; i++) { 28 if(!mark[i]) pri[pricnt++]=mark[i]=i; 29 for(int j=0; pri[j]*i<M; j++) { 30 mark[i*pri[j]]=pri[j]; 31 if(!(i%pri[j])) break; 32 } 33 } 34 } 35 int rat[1024]; 36 int main(){ 37 sieve_primes(); 38 int t,n,m,q,c,tmp,id; 39 while(~scanf("%d",&t)){ 40 while(t--){ 41 scanf("%d%d%d",&n,&m,&q); 42 A.clear(); 43 while(q--){ 44 scanf("%d",&tmp); 45 A.insert(tmp); 46 } 47 scanf("%d",&q); 48 B.clear(); 49 while(q--){ 50 scanf("%d",&tmp); 51 B.insert(tmp); 52 } 53 scanf("%d",&q); 54 for(int i=0;i<4;i++){ 55 xiaosai[i].clear(); 56 } 57 while(q--){ 58 scanf("%s%d",op,&id); 59 xiaosai[id].insert((string)op); 60 } 61 for(int i=0;i<n;i++){ 62 p[i].val=0; 63 scanf("%s",op); 64 p[i].name=(string)op; 65 scanf("%s",op); 66 for(int j=1;j<=3;j++){ 67 if(xiaosai[j].count((string)op)){ 68 p[i].val+=defen[j]; 69 break; 70 } 71 } 72 scanf("%s",op); 73 if(op[0]=='F') p[i].val+=33; 74 scanf("%d%d",&q,&c); 75 while(q--){ 76 scanf("%d",&tmp); 77 if(A.count(tmp)){ 78 p[i].val+=2.5; 79 continue; 80 } 81 if(B.count(tmp)){ 82 p[i].val+=1.5; 83 continue; 84 } 85 if(mark[tmp]==tmp){ 86 p[i].val+=1; 87 continue; 88 } 89 p[i].val+=0.3; 90 } 91 for(int j=0;j<c;j++){ 92 scanf("%d",&rat[j]); 93 } 94 sort(rat,rat+c); 95 if(c>2){ 96 p[i].val+=max(0.0,(rat[c-3]-1200.0)/100.0)*1.5; 97 } 98 } 99 sort(p,p+n); 100 for(int i=0;i<m;i++){ 101 cout<<p[i].name; 102 printf(" %.3f\n",p[i].val); 103 } 104 } 105 } 106 return 0; 107 }
Break Standard Weight http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5009
set
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio> 2 #include<algorithm> 3 #include<set> 4 using namespace std; 5 set<int> my; 6 int solve(int x,int y){ 7 int res=0; 8 for(int i=1;i+i<=x;i++){ 9 my.clear(); 10 int a=i,b=x-i,c=y; 11 my.insert(a); 12 my.insert(b); 13 my.insert(c); 14 my.insert(abs(a+b)); 15 my.insert(abs(a-b)); 16 my.insert(abs(a+c)); 17 my.insert(abs(a-c)); 18 my.insert(abs(b+c)); 19 my.insert(abs(b-c)); 20 my.insert(abs(a+b+c)); 21 my.insert(abs(a+b-c)); 22 my.insert(abs(a-b+c)); 23 my.insert(abs(a-b-c)); 24 my.erase(0); 25 int cnt=my.size(); 26 res=max(res,cnt); 27 } 28 return res; 29 } 30 int main(){ 31 int t,x,y; 32 while(~scanf("%d",&t)){ 33 while(t--){ 34 scanf("%d%d",&x,&y); 35 printf("%d\n",max(solve(x,y),solve(y,x))); 36 } 37 } 38 return 0; 39 }
Density of Power Network http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5011
set
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio> 2 #include<set> 3 using namespace std; 4 const int M=512; 5 struct P{ 6 int x,y; 7 friend bool operator <(const P &a,const P &b){ 8 return a.x<b.x||(a.x==b.x&&a.y<b.y); 9 } 10 }p[M]; 11 set<P> my; 12 int main(){ 13 int t,n,m; 14 while(~scanf("%d",&t)){ 15 while(t--){ 16 scanf("%d%d",&n,&m); 17 for(int i=0;i<m;i++){ 18 scanf("%d",&p[i].x); 19 } 20 for(int i=0;i<m;i++){ 21 scanf("%d",&p[i].y); 22 } 23 my.clear(); 24 for(int i=0;i<m;i++){ 25 if(p[i].x>p[i].y) swap(p[i].x,p[i].y); 26 my.insert(p[i]); 27 } 28 printf("%.3f\n",my.size()*1.0/n); 29 } 30 } 31 return 0; 32 }
Friends http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5013
暴力加边
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio> 2 #include<cstring> 3 #define mt(a,b) memset(a,b,sizeof(a)) 4 const int M=128; 5 bool mat[M][M]; 6 void add(int u,int v){ 7 mat[u][v]=mat[v][u]=true; 8 } 9 int main(){ 10 int t,n,m,K,u,v; 11 while(~scanf("%d",&t)){ 12 while(t--){ 13 scanf("%d%d%d",&n,&m,&K); 14 mt(mat,0); 15 while(m--){ 16 scanf("%d%d",&u,&v); 17 add(u,v); 18 } 19 int ans=0; 20 bool flag=true; 21 while(flag){ 22 flag=false; 23 for(int i=0;i<n;i++){ 24 for(int j=i+1;j<n;j++){ 25 if(!mat[i][j]){ 26 int sum=0; 27 for(int k=0;k<n;k++){ 28 if(k!=i&&k!=j&&mat[i][k]&&mat[k][j]){ 29 sum++; 30 } 31 } 32 if(sum>=K){ 33 ans++; 34 flag=true; 35 add(i,j); 36 } 37 } 38 } 39 } 40 } 41 printf("%d\n",ans); 42 } 43 } 44 return 0; 45 }
Hard to Play http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5015
求最大最小值
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio> 2 int solve(int point,int times,int &combo){ 3 int res=0; 4 for(int i=0;i<times;i++,combo++){ 5 res+=point*(combo*2+1); 6 } 7 return res; 8 } 9 int main(){ 10 int t,a,b,c,combo,big,sma; 11 while(~scanf("%d",&t)){ 12 while(t--){ 13 scanf("%d%d%d",&a,&b,&c); 14 combo=sma=0; 15 sma+=solve(300,a,combo); 16 sma+=solve(100,b,combo); 17 sma+=solve(50,c,combo); 18 combo=big=0; 19 big+=solve(50,c,combo); 20 big+=solve(100,b,combo); 21 big+=solve(300,a,combo); 22 printf("%d %d\n",sma,big); 23 } 24 } 25 return 0; 26 }
In 7-bit http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5016
注意la==0
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio> 2 #include<cstring> 3 const int M=3000010; 4 char a[M]; 5 int main(){ 6 int t; 7 while(~scanf("%d",&t)){ 8 getchar(); 9 while(t--){ 10 gets(a); 11 int la=strlen(a); 12 if(la==0){ 13 puts("00"); 14 continue; 15 } 16 int len=la; 17 while(len>0){ 18 int now=len%128; 19 len/=128; 20 if(len) now|=128; 21 printf("%02X",now); 22 } 23 for(int i=0;i<la;i++){ 24 printf("%02X",a[i]); 25 } 26 puts(""); 27 } 28 } 29 return 0; 30 }
Java Beans http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5017
n个人坐成环,求连续m个和最大
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio> 2 #include<algorithm> 3 using namespace std; 4 const int M=410; 5 int a[M]; 6 int main(){ 7 int t,n,m; 8 while(~scanf("%d",&t)){ 9 while(t--){ 10 scanf("%d%d",&n,&m); 11 for(int i=0;i<n;i++){ 12 scanf("%d",&a[i]); 13 a[i+n]=a[i]; 14 } 15 int ans=0; 16 for(int i=0;i<n;i++){ 17 int sum=0; 18 for(int j=0;j<m;j++){ 19 sum+=a[i+j]; 20 } 21 ans=max(ans,sum); 22 } 23 printf("%d\n",ans); 24 } 25 } 26 return 0; 27 }
end