Codeforces Round #349 (Div. 2)

链接:http://codeforces.com/contest/667

A. Pouring Rain题意:有一个圆柱体的杯子,直径为d,里面已经有的水高度为h,现在每秒种喝水v毫升,同时因为下雨,水的高度每秒升高e厘米。问是否水会喝完,如果喝完,那么用时是多少?

题解:先算出已有水的体积V=π*(d/2)2 *h,然后把水增加的速度转化为毫升,E=π*(d/2)2 *e。那么水量变化的相对速率就是D=V-E。

如果D<=0,那么肯定是喝不完的,当D>0时,用时是V/D。

 1 /*A*/
 2 #include<cstdio>
 3 using namespace std;
 4 
 5 const double PI=3.1415926;
 6 
 7 int main()
 8 {
 9     int d,h,v,e;
10     while(scanf("%d%d%d%d",&d,&h,&v,&e)!=EOF)
11     {
12         double r=(double)d/2;
13         double S=PI*r*r;
14         double V=S*h; 
15         double E=S*e;
16         if(E>=v)
17         {
18             printf("NO
");
19             continue;
20         }
21         else
22         {
23             
24             double D=v-E;
25             double ans=V/D;
26             printf("YES
");
27             printf("%.6lf
",ans);
28         }
29         return 0;
30     }
31 }
View Code

B. Coat of Anticubism

题意:给你一些木棍,你要用这些木棍组成一个凸多边形,两根木棍之间的夹角可以等于180°(两根组成一根)。实际上给的木棍肯定是不可以构成凸多边形的,需要再加一根,问加的这根最短是多少。

题解:直接用这些木棍来组成三角形,先把已有的木棍分成尽量相等的两堆,也就是三角形的两条边。因为三角形两边之和大于第三边,所以第三条边就是两堆的差值加1。要分两堆尽量相等,用贪心的方法,先从小到大排序,从大的开始放,当两堆相等时放左边,不等时放小的那一边。

 1 /*B*/
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<cmath>
 6 using namespace std;
 7 
 8 const int maxn=100000+10;
 9 
10 int main()
11 {
12     int n;
13     while(scanf("%d",&n)!=EOF)
14     {
15         int a[maxn];
16         for(int i=0;i<n;i++)
17             scanf("%d",&a[i]);
18         sort(a,a+n);
19         long long A=0,B=0;
20         for(int i=n-1;i>=0;i--)
21         {
22             if(A==B)
23                 A+=a[i];
24             else if(A>B)
25                 B+=a[i];
26             else
27                 A+=a[i];
28         }
29         long long d=A-B;
30         d=abs(d);
31         printf("%I64d
",d+1);
32     }
33     return 0;
34 }
View Code
原文地址:https://www.cnblogs.com/yepiaoling/p/5448369.html