首页 > 其他 > 详细

计蒜客 UCF 2015

时间:2020-02-27 21:33:18      阅读:70      评论:0      收藏:0      [点我收藏+]

#A.Find the twins

技术分享图片

 

 

# 题意

找出每个序列是否有特定的值

 

# 题解

坑,原始序列输出的时候每一行最后一个不能有空格

 

 1 #include<bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4 const int N=2e5+10;
 5 int a[15];
 6 int n;
 7 int main(){
 8     n=10;
 9     int t;
10     cin>>t;
11 
12     for(int k=1;k<=t;k++){
13         bool z=0,m=0;
14         for(int i=1;i<=n;i++){
15             cin>>a[i];
16             if(a[i]==18)
17                 m=1;
18             if(a[i]==17)
19                 z=1;
20         }
21 
22         for(int i=1;i<=n;i++) {
23             if(i!=n)
24               printf("%d ",a[i]);
25             else
26                 printf("%d",a[i]);
27         }
28         puts("");
29         if(m&&z) {
30                 puts("both");
31         }
32         else if(m) {
33             puts("mack");
34             }
35         else if(z) {
36                 puts("zack");
37         }
38         else {
39                 puts("none");
40         }
41         puts("");
42     }
43 
44 }

 

 #B.Medal Ranking

技术分享图片

 

#题解

水题一样还是最后一行空格

 

 1 #include<bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4 const int N=2e5+10;
 5 int a[15];
 6 int n;
 7 int main(){
 8     n=10;
 9     int t;
10     cin>>t;
11 
12     for(int k=1;k<=t;k++){
13         bool cnt=0,col=0;
14         int m1,m2,m3;
15         int r1,r2,r3;
16         cin>>m1>>m2>>m3;
17         cin>>r1>>r2>>r3;
18         int summ=m1+m2+m3;
19         int sumr=r1+r2+r3;
20         if(summ>sumr)
21             cnt=1;
22 
23         if(m1 > r1)
24             col=1;
25         if(m1 == r1){
26             if(m2>r2)
27                 col=1;
28             if(m2==r2){
29                 if(m3>r3)
30                     col=1;
31             }
32         }
33 
34         cout<<m1<< <<m2<< <<m3<< <<r1<< <<r2<< <<r3<<endl;
35         if(col && cnt)
36             cout<<"both"<<endl;
37         else if(cnt)
38             cout<<"count"<<endl;
39         else if(col)
40             cout<<"color"<<endl;
41 
42         else cout<<"none"<<endl;
43         puts("");
44     }
45 
46 }

 

# C. Cookies

技术分享图片

 

 技术分享图片

 

 

 

 # 题解

饼干不够就切

 

 1 #include<bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4 const int N=2e5+10;
 5 int main(){
 6     int t;
 7     cin>>t;
 8     for(int i=1;i<=t;i++){
 9         int n,cnt;
10         cin>>n>>cnt;
11         printf("Practice #%d: %d %d\n",i,n,cnt);
12         int m;
13         cin>>m;
14         for(int j=1;j<=m;j++){
15             int x;
16             cin>>x;
17             while(x>=cnt)
18                 cnt*=2;
19             cnt-=x;
20             cout<<x<< <<cnt<<endl;
21         }
22         puts("");
23     }
24 
25 }

 

 # D. Lemonade Stand

技术分享图片

 

 

技术分享图片

 

 

 

 

# 题意

一个柠檬水店,每一杯柠檬水的制作需要糖和柠檬,知道每天都会来多少人,每天柠檬和糖的原材料价格都不一样,

每天可以买任意多的和任意少的,每天的所有客人都要被满足,每天的价格是单个柠檬的价格和80 盎司糖的价格,剩下的原料第二天可以使用。

 

# 题解

从前往后只记录之前的价格的最小值即可,因为糖只能一包一包买也就是80盎司,

第二天可以使用第一天剩余的,并且只能第二天使用,剩余的一定小于80盎司。

 

 1 #include <bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4 struct node{
 5     ll cnt,pl,ps;
 6 }day[1010];
 7 void work(){
 8     ll d,x,y;
 9     cin>>d>>x>>y;
10     day[0].pl=INT_MAX;
11     day[0].ps=INT_MAX;
12     for(int i=1;i<=d;i++){
13         cin>>day[i].cnt>>day[i].pl>>day[i].ps;
14         day[i].pl=min(day[i].pl,day[i-1].pl);
15         day[i].ps=min(day[i].ps,day[i-1].ps);
16     }
17 
18     ll ans=0,now_r=0;
19     for(int i=1;i<=d;i++){
20 
21         ans+=day[i].cnt*x*day[i].pl;
22         now_r-=day[i].cnt * y;
23         while(now_r<0){
24             now_r+=80;
25             ans+=day[i].ps;
26         }
27         //ll need=day[i].cnt*y;
28         //need-=now_r;
29 
30         /*if(need > 80 && need % 80){
31             now_r = (need/80+1)*80 - need;
32             ans+=(need / 80 +1) * day[i].ps;
33         }
34         else if(need > 80 && !(need % 80)){
35             now_r= 0;
36             ans+=need/80 * day[i].ps;
37         }
38         else if(need<80){
39             now_r=80-need;
40             ans+=day[i].ps;
41         }
42          */
43 
44     }
45     cout<<ans<<endl;
46 }
47 int main(){
48     int t;
49     cin>>t;
50     while(t--){
51         work();
52     }
53 }

 

# E.Rain Gauge

技术分享图片

 

技术分享图片

 

 

# 题意

 即给定一个正方形和圆,求圆覆盖正方形的面积

 

题解

分成三种情况,两种正好的情况直接计算,另一种求出来出来的面积,圆的面积减去即可

利用反三角函数,反三角函数返回的是弧度制 

 

 1 #include<bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4 const double pi=3.14159265358979;
 5 int main(){
 6     int t;
 7     cin>>t;
 8     for(int i=1;i<=t;i++){
 9         double s,r;
10         cin>>s>>r;
11         double d=s/2;
12         double p=sqrt(2)*d;
13         double ans;
14         if(r>=p) {
15             ans = s*s;
16         }
17         else if(r<=d)
18             ans=pi*r*r;
19         else if(r<p && r>d){
20             double c= sqrt(r*r-d*d);
21             double rec=c*d;
22             double jd=2*acos(d/r);
23             double cir=jd*r*r/2;
24             double la=cir-rec;
25             ans = pi*r*r-4*la;
26         }
27         cout<<fixed<<setprecision(2)<<ans<<endl;
28     }
29 
30 }

 

G.Towers of Hanoi grid

技术分享图片

 

技术分享图片

 

 

技术分享图片

 

 

 

 

# 题意 

 

 

n*n的网格,从(1,1)中的d个从上到下递减的塔移动到(n,n)点上去,

除了(1,1)和(n,n)以外其余的点只能放一个塔,如果能移动求最少的移动次数,如果不行输出impossible

 

# 题解

画图易知必须有一条可行的哈密顿路径供最下面的塔移动到(n,n)

 

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 using namespace std;
 5 int main(){
 6     int t;
 7     cin>>t;
 8     for(int i=1;i<=t;i++){
 9         int d,n;
10         cin>>d>>n;
11         if(d > (n-1)*(n-1)+1)
12             cout<<"Grid #"<<i<<": "<<"impossible"<<endl;
13         else
14             cout<<"Grid #"<<i<<": "<<d*(n-1)*2<<endl;
15         puts("");
16     }
17     return 0;
18 
19 }

 

计蒜客 UCF 2015

原文:https://www.cnblogs.com/hhyx/p/12374192.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!