UPC2018组队训练赛第九场
Posted scott527407973
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UPC2018组队训练赛第九场相关的知识,希望对你有一定的参考价值。
题目来自2018广西省赛
A题:Welcome to Collegiate Programming Contest
1 #include <iostream> 2 3 using namespace std; 4 5 int main() 6 { 7 int n; 8 int t; 9 cin>>t; 10 while(t--) 11 { 12 cin>>n; 13 for(int i=0;i<n;i++) 14 { 15 if(i) 16 { 17 cout<<" "; 18 } 19 cout<<"AC"; 20 } 21 cout<<endl; 22 } 23 return 0; 24 }
B题:Practice
1 #include <iostream> 2 #include<bits/stdc++.h> 3 using namespace std; 4 const int N=6; 5 struct node{ 6 int time; 7 int value; 8 }op[N]; 9 bool cmp1(node a,node b) 10 { 11 if(a.time==b.time) 12 { 13 return a.value>b.value; 14 } 15 return a.time<b.time; 16 } 17 bool cmp2(node a,node b) 18 { 19 if(a.value==b.value) 20 { 21 return a.time<b.time; 22 } 23 return a.value>b.value; 24 } 25 int main() 26 { 27 int t; 28 scanf("%d",&t); 29 int n,m; 30 while(t--) 31 { 32 scanf("%d %d",&n,&m); 33 for(int i=1;i<=n;i++) 34 { 35 scanf("%d",&op[i].time); 36 } 37 for(int i=1;i<=n;i++) 38 { 39 scanf("%d",&op[i].value); 40 } 41 sort(op+1,op+1+n,cmp1); 42 int i=1,ans1=0,ans2=0,mm=m; 43 while(mm>=op[i].time) 44 { 45 ans1+=op[i].value; 46 mm-=op[i].time; 47 i++; 48 } 49 i=1; 50 mm=m; 51 sort(op+1,op+1+n,cmp2); 52 while(mm>=op[i].time) 53 { 54 ans2+=op[i].value; 55 mm-=op[i].time; 56 i++; 57 } 58 if(ans1==ans2) 59 { 60 printf("SAME "); 61 } 62 else if(ans1>ans2) 63 { 64 printf("A "); 65 } 66 else 67 { 68 printf("B "); 69 } 70 } 71 return 0; 72 } 73
C题:Team Match
1 #include <iostream> 2 #include<bits/stdc++.h> 3 using namespace std; 4 const int N=10; 5 struct node 6 { 7 int x,y,z; 8 }; 9 int a[2*N],vis[2*N]; 10 int ans,n,m; 11 bool cmp(int x,int y) 12 { 13 return x>y; 14 } 15 int main() 16 { int t; 17 scanf("%d",&t); 18 while(t--) 19 { 20 scanf("%d %d",&n,&m); 21 for(int i=1; i<=n; i++) 22 { 23 scanf("%d",&a[i]); 24 } 25 sort(a+1,a+1+n,cmp); 26 27 ans=0; 28 29 for(int i=1; i<=n; i++) 30 { 31 int x=-1,y=-1,z=-1; 32 for(int j=i+1; j<=n; j++) 33 { 34 for(int k=j+1; k<=n; k++) 35 { 36 if(vis[i]==0&&vis[j]==0&&vis[k]==0) 37 { 38 if(a[i]*3+a[j]*2+a[k]>=m) 39 { 40 x=i; 41 y=j; 42 z=k; 43 } 44 } 45 } 46 } 47 if(x==-1) 48 { 49 break; 50 } 51 else 52 { 53 ans++; 54 vis[x]=1; 55 vis[y]=1; 56 vis[z]=1; 57 } 58 } 59 printf("%d ",ans); 60 memset(vis,0,sizeof(vis)); 61 } 62 return 0; 63 }
D题:Team Name
E题:Travel
1 #include <iostream> 2 #include<bits/stdc++.h> 3 using namespace std; 4 5 int main() 6 { 7 int t,n; 8 scanf("%d",&t); 9 while(t--) 10 { 11 scanf("%d",&n); 12 if(n==2||n==3) 13 { 14 printf("1 "); 15 continue; 16 } 17 n-=2; 18 int ans=0,tmp; 19 if(n%2==0) 20 { 21 tmp=pow(2,n/2); 22 ans=max(ans,tmp); 23 } 24 else if(n%2==1) 25 { 26 tmp=pow(2,n/2-1); 27 ans=max(ans,tmp*3); 28 } 29 if(n%3==0) 30 { 31 tmp=pow(3,n/3); 32 ans=max(ans,tmp); 33 } 34 else if(n%3==1) 35 { 36 tmp=pow(3,n/3-1); 37 ans=max(ans,tmp*4); 38 } 39 else 40 { 41 tmp=pow(3,n/3); 42 ans=max(ans,tmp*2); 43 } 44 printf("%d ",ans); 45 } 46 return 0; 47 }
F题:Stadium
1 #include <iostream> 2 #include<bits/stdc++.h> 3 using namespace std; 4 const int N=10; 5 double a[N]; 6 bool cmp(double x,double y) 7 { 8 return x>y; 9 } 10 bool check(double aa,double b,double c) 11 { 12 if(aa+b>c&&aa+c>b&&b+c>aa) 13 { 14 return true; 15 } 16 return false; 17 } 18 int main() 19 { 20 int t; 21 scanf("%d",&t); 22 while(t--) 23 { 24 for(int i=1;i<=4;i++) 25 { 26 scanf("%lf",&a[i]); 27 } 28 sort(a+1,a+5,cmp); 29 double ans=0; 30 for(int i=1;i<=3;i++) 31 { 32 for(int j=i+1;j<=4;j++) 33 { 34 double aa,b,c; 35 b=0; 36 aa=a[i]-a[j]; 37 for(int k=1;k<=4;k++) 38 { 39 if(k!=i&&k!=j&&b==0) 40 { 41 b=a[k]; 42 } 43 else if(k!=i&&k!=j&&b!=0) 44 { 45 c=a[k]; 46 } 47 } 48 if(check(aa,b,c)) 49 { 50 double cos1=(b*b+c*c-aa*aa)/(2*b*c); 51 double sin1=sqrt((1-cos1*cos1)); 52 double area=b*c*sin1; 53 double h=area/aa; 54 area/=2; 55 area+=a[j]*h; 56 ans=max(ans,area); 57 } 58 } 59 } 60 if(ans==0) 61 { 62 printf("IMPOSSIBLE "); 63 continue; 64 } 65 printf("%.2lf ",ans); 66 } 67 return 0; 68 }
G题:GXBalloons
1 #include <bits/stdc++.h> 2 using namespace std; 3 struct node 4 { 5 int x,y,pos; 6 }mp[10005]; 7 bool cmp1(node a,node b) 8 { 9 return a.x<b.x; 10 } 11 bool cmp2(node a,node b) 12 { 13 return a.y<b.y; 14 } 15 int fa[10005]; 16 int get(int x) 17 { 18 if(x==fa[x])return x; 19 return fa[x]=get(fa[x]); 20 } 21 void Union(int x,int y) 22 { 23 fa[get(x)]=get(y); 24 } 25 int main() 26 { 27 int t,n,k; 28 scanf("%d",&t); 29 while(t--) 30 { 31 scanf("%d%d",&n,&k); 32 for(int i=1;i<=n;i++) 33 { 34 scanf("%d%d",&mp[i].x,&mp[i].y); 35 mp[i].pos=i; 36 } 37 for(int i=1;i<=n;i++) 38 { 39 fa[i]=i; 40 } 41 sort(mp+1,mp+1+n,cmp1); 42 for(int i=2;i<=n;i++) 43 { 44 if(mp[i].x-mp[i-1].x<=k) 45 { 46 Union(mp[i].pos,mp[i-1].pos); 47 } 48 } 49 sort(mp+1,mp+1+n,cmp2); 50 for(int i=2;i<=n;i++) 51 { 52 if(mp[i].y-mp[i-1].y<=k) 53 { 54 if(get(mp[i].pos)!=get(mp[i-1].pos)) 55 { 56 Union(mp[i].pos,mp[i-1].pos); 57 } 58 } 59 } 60 int ans=0; 61 for(int i=1;i<=n;i++) 62 { 63 // cout<<fa[i]<<" "<<get(mp[i].pos)<<endl; 64 if(i==fa[i]) 65 ans++; 66 } 67 printf("%d ",ans); 68 } 69 // cout << "Hello world!" << endl; 70 return 0; 71 }
H题:GXBoard
1 #include <iostream> 2 #include<bits/stdc++.h> 3 using namespace std; 4 5 int main() 6 { 7 int t; 8 int n; 9 string s[105]; 10 cin>>t; 11 while(t--) 12 { 13 cin>>n; 14 int ans=0; 15 for(int i=0;i<n;i++) 16 { 17 cin>>s[i]; 18 ans+=s[i].size(); 19 } 20 cout<<ans<<endl; 21 } 22 return 0; 23 }
I题:Rank LED
J题:Pot
求所有数的gcd,然后乘以n
1 #include <iostream> 2 #include<bits/stdc++.h> 3 using namespace std; 4 int t,n,x[200]; 5 int gcd(int a,int b) 6 { 7 return b?gcd(b,a%b):a; 8 } 9 int main() 10 { 11 cin>>t; 12 while(t--) 13 { 14 cin>>n; 15 int p=1; 16 for(int i=0;i<n;i++) 17 { 18 cin>>x[i]; 19 // p=gcd(p,x); 20 } 21 if(n==1) 22 { 23 cout<<x[0]<<endl; 24 continue; 25 } 26 p=gcd(x[0],x[1]); 27 for(int i=2;i<n;i++) 28 p=gcd(x[i],p); 29 int ans=p*n; 30 cout<<ans<<endl; 31 } 32 return 0; 33 }
以上是关于UPC2018组队训练赛第九场的主要内容,如果未能解决你的问题,请参考以下文章
2018年第四阶段组队训练赛第三场(BAPC2017 Preliminaries)