A
#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <cstring> #include<iomanip> using namespace std; int t,n,m,r,s,q,p,c; double score[505]; int rList[505],sList[505],jamList[1005]; class Competition { public: int rank; string team; }; Competition com[505]; class People { public: string team; string name; char sex; double score; }; People peo[505]; bool cmp(People a,People b) { return a.score > b.score; } double Max(double a,double b) { if(a>b) return a; else return b; } bool cmp2(int a,int b) { return a>b; } bool Prime(int x) { for(int i=2; i<=sqrt(x); i++) { if(x % i==0) return 0; } return 1; } double jam(int r) { return Max(0,((r-1200)/100.0)*1.5); } bool isR(int id) { for(int i=0; i<r; i++) { if(id==rList[i]) return 1; } return 0; } bool isS(int id) { for(int i=0; i<s; i++) { if(id==sList[i]) return 1; } return 0; } int main() { cin >> t; while(t--) { memset(rList,0,sizeof(rList)); memset(sList,0,sizeof(sList)); cin >> n >> m; cin>>r; for(int i=0; i<r; i++) { cin >> rList[i]; } cin >> s; for(int i=0; i<s; i++) { cin >> sList[i]; } // puts("ok"); cin >> q; for (int j=0; j<q; j++) { cin >> com[j].team ; cin >> com[j].rank; } for(int i=0; i<n; i++) { peo[i].score = 0; } int x ,y ,id ; for(int i=0; i<n; i++) { memset(jamList,0,sizeof(jamList)); cin>>peo[i].name>>peo[i].team>>peo[i].sex; cin>>x>>y; if(peo[i].sex == 'F') peo[i].score+=33; while (x--) { cin>>id; if(isR(id)) peo[i].score+=2.5; else if(isS(id)) peo[i].score +=1.5; else if(Prime(id)) peo[i].score +=1; else peo[i].score += 0.3; } for(int t=0; t<q; t++) { if(peo[i].team==com[t].team) { if(com[t].rank==1) { peo[i].score+=36; } else if(com[t].rank==2) { peo[i].score+=27; } else if(com[t].rank==3) { peo[i].score+=18; } } } for(int j=0; j<y; j++) { cin>>jamList[j]; } sort(jamList,jamList+y,cmp2); peo[i].score+=jam(jamList[2]); } sort(peo,peo+n,cmp); for(int i=0; i<m; i++) { cout<<peo[i].name<<" "<<setiosflags(ios::fixed)<<setprecision(3)<<peo[i].score<<endl; } } return 0; }
B
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; int hash[205]; int a[3]; int count() { int sum=0; int i,j,k; for (i=0;i<3;i++) { if (!hash[a[i]]) { sum++; hash[a[i]]=1; } } for (j=0;j<3;j++) { for (k=j+1;k<3;k++) { int tt=a[j]+a[k]; int kk=a[k]-a[j]; if (!hash[tt]) { sum++; hash[tt]=1; } if (!hash[kk]) { sum++; hash[kk]=1; } } } int whole=a[0]+a[1]+a[2]; if (!hash[whole]) {sum++;hash[whole]=1;} for (i=0;i<3;i++) { for (j=i+1;j<3;j++) { int ww=3-i-j; int temp=a[i]+a[j]-a[ww]; if (temp<0) temp=-temp; if (!hash[temp]) { sum++; hash[temp]=1; } } } return sum; } int main() { int t; scanf("%d",&t); while (t--) { int x,y; scanf("%d %d",&x,&y); int i,j; int ans=0; for (i=1;i<=x/2;i++) { memset(hash,0,sizeof hash); hash[0]=1; a[0]=i; a[1]=x-i; a[2]=y; sort(a,a+3); int sum=count(); if (ans<sum) ans=sum; } for (j=1;j<=y/2;j++) { memset(hash,0,sizeof hash); hash[0]=1; a[0]=j; a[1]=y-j; a[2]=x; sort(a,a+3); int s2=count(); if (ans<s2) ans=s2; } printf("%d ",ans); } return 0; }
D
#include <iostream> #include <cstring> #include <iomanip> using namespace std; int map[505][505]; int start[505]; int end[505]; int main() { int t; cin>>t; int n,m; while(t--) { memset(map,0,sizeof(map)); cin>>n>>m; for(int i = 1; i <= m; i++) { cin>>start[i]; } for(int i = 1; i<= m; i++) { cin>>end[i]; } for(int i = 1; i <= m; i++) { map[start[i]][end[i]] = 1; } int count = 0; for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) { if(map[i][j]) { count++; map[j][i] = 0; } } } cout<<fixed<<setprecision(3)<<count*1.0/n<<endl; } return 0; }
F
#include <cstdio> #include <iostream> #include <cstring> using namespace std; bool f[105][105]; bool vis[1050][1050]; int n,m,k; int ans; int judge(int x,int y) { int i,j; int sum=0; for (i=0;i<n;i++) { if (f[x][i]&&f[y][i]) sum++; if (sum>=k) break; } if (sum>=k) {f[x][y]=f[y][x]=1;return 1;} else return 0; } int makef() { int j,w; bool flag=false; for (j=0;j<n;j++) { for (w=j+1;w<n;w++) { if (j==w) continue; //cout<<j<<" "<<w<<" "<<f[j][w]<<endl; if (vis[j][w]||vis[w][j]) continue; //vis[j][w]=1; if (f[j][w]==0) { int tt=judge(j,w); ans+=tt; if (tt>0) { vis[j][w]=vis[w][j]=1; flag=1; } } } } if (flag) makef(); } int main() { int t; scanf("%d",&t); while (t--) { scanf("%d %d %d",&n,&m,&k); int i,j,w; for (i=0;i<=n;i++) { for (j=0;j<=n;j++) {f[i][j]=0;vis[i][j]=0;} } for (i=0;i<m;i++) { int a,b; scanf("%d %d",&a,&b); f[a][b]=f[b][a]=1; // cout<<a<<" "<<b<<endl; } ans=0; makef(); printf("%d ",ans); } return 0; }
H
#include <iostream> using namespace std; int main() { int t; cin>>t; int A,B,C; while(t--) { cin>>A>>B>>C; int sum = A+B+C; int com = 0; int max = 0; int min = 0; for(int i = 0 ; i < C; i++) { max += 50*(com*2 + 1); com++; } for(int i = 0 ; i < B; i++) { max += 100*(com*2 + 1); com++; } for(int i =0 ; i < A; i++) { max += 300*(com*2 + 1); com++; } com = 0; for(int i = 0 ; i < A; i++) { min += 300*(com*2 + 1); com++; } for(int i = 0 ; i < B; i++) { min += 100*(com*2 + 1); com++; } for(int i =0 ; i < C; i++) { min += 50*(com*2 + 1); com++; } cout<<min<<" "<<max<<endl; } return 0; }
I
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <iostream> using namespace std; char str[3000005]; int main() { int t; scanf("%d",&t); // cout << t; getchar(); while(t--) { gets(str); int len = strlen(str); if(!len) { puts("00"); continue; } while(len) { int tmp = len & 127; len = len >> 7; if(len) { tmp = tmp | 128; } if(tmp<16) printf("0"); printf("%X",tmp); } len = strlen(str); for(int i=0; i<len; i++) { printf("%X",str[i]); } puts(""); } return 0; }
J
#include <iostream> #include <cstdio> using namespace std; int num[205]; int main() { int n,m; int t; scanf("%d",&t); while (t--) { scanf("%d %d",&n,&m); int i,j; for (i=1;i<=n;i++) scanf("%d",&num[i]); int cur=0; int ans=0; for (i=1;i<=n;i++) { cur=0; for (j=0;j<m;j++) { int temp; temp=i+j; if (temp<=n) cur+=num[temp]; else { temp=temp%n; cur+=num[temp]; } } if (cur>ans) ans=cur; } printf("%d ",ans); } return 0; }