Codeforces Round #280 (Div. 2)

 2023-09-10 阅读 18 评论 0

摘要:B. Vanya and Lanterns code 128。题意:给出n个路灯,街道的长度,求出路灯的最小照射半径,使得整条街道都被照亮。 求出起点到第一盏灯的距离---n盏灯之间的距离/2---最后一盏灯到街尾的距离,找出这些值里面的最大值。 1 #include<iostr

B. Vanya and Lanterns

code 128。题意:给出n个路灯,街道的长度,求出路灯的最小照射半径,使得整条街道都被照亮。

求出起点到第一盏灯的距离---n盏灯之间的距离/2---最后一盏灯到街尾的距离,找出这些值里面的最大值。

 1 #include<iostream>  
 2 #include<cstdio>  
 3 #include<cstring> 
 4 #include <cmath>   
 5 #include<algorithm>  
 6 using namespace std;
 7 
 8 typedef long long LL;
 9 int a[10005],b[10005];
10 
11 int main()
12 {
13     int n,l,i,x,y;
14     double d;
15     cin>>n>>l;
16     for(i=1;i<=n;i++) cin>>a[i];
17     sort(a+1,a+n+1);
18     int maxd=-1;
19     for(i=1;i<n;i++)
20     {
21          b[i]=a[i+1]-a[i];        
22         maxd=max(maxd,b[i]);
23     }
24     x=a[1]-0;
25     y=l-a[n];
26 //    printf("x=%d\n",x);
27 //    printf("y=%d\n",y);
28 //    printf("maxd=%d\n",maxd);
29 if(2*x>maxd&&x>=y) printf("%.7lf\n",x*1.0);
30 else if(y>=x&&2*y>maxd) printf("%.7lf\n",y*1.0);
31      
32 else printf("%.7lf\n",maxd*0.5);
33     
34 }
View Code

 

C. Vanya and Exams

题意:给出n场考试,每场考试只能考到的最高分r,平均分 再给出现在每场考试的成绩a[i],提高一分需要做的试卷b[i],问至少需要做多少张试卷才能每科都达到平均分

先按照b[i]从小到大排序,再算出需要做的试卷数量,模拟做试卷

 1 #include<iostream>  
 2 #include<cstdio>  
 3 #include<cstring> 
 4 #include <cmath>   
 5 #include<algorithm>  
 6 using namespace std;
 7 
 8 typedef long long LL;
 9 struct node{
10     int x,y;
11 } a[100005];
12 
13 int cmp(node n1,node n2){
14     if(n1.y!=n2.y) return n1.y<n2.y;
15     return n1.x<n2.x;
16 }
17 
18 int main()
19 {
20     LL tmp=0,sum=0,ans=0,c,i, n,r,avg;
21     cin>>n>>r>>avg;
22     for(i=1;i<=n;i++) {
23         cin>>a[i].x>>a[i].y;
24         sum+=a[i].x;
25     }
26     sort(a+1,a+n+1,cmp);
27     ans=n*avg-sum;
28     
29 //    for(i=1;i<=n;i++)
30 //    {
31 //        printf("%d %d\n",a[i].x,a[i].y);
32 //    }
33 //    printf("ans=%d\n\n",ans);
34     if(ans<=0) printf("0\n");
35     else
36     {
37         for(i=1;i<=n;i++){
38             if(ans<=(r-a[i].x)){
39                 tmp+=ans*a[i].y;
40                 c=ans;
41             }
42             else{
43                 tmp+=(r-a[i].x)*a[i].y;
44                 c=r-a[i].x;
45             }
46             ans=ans-c;
47             if(ans<=0) break;
48         }
49         printf("%I64d\n",tmp);        
50     }
51 }
View Code

 

D. Vanya and Computer Game

题意:给出n只怪兽,vanya打怪的频率为x次每秒,给怪兽的伤害是1/x vova打怪的频率为y次每秒,给怪的伤害是1/y 再给出每只怪兽最多被伤害的次数 问第i只怪兽是被谁打败的

看的题解= =

可以转化为vanya每y秒伤害一次怪兽,vova每x秒伤害一次怪兽 再在时间轴上查找被攻击的次数,肯定是能被x或者y或者两者都整除的

 1 #include<iostream>  
 2 #include<cstdio>  
 3 #include<cstring> 
 4 #include <cmath>   
 5 #include<algorithm>  
 6 using namespace std;
 7 
 8 typedef long long LL;
 9 LL i,n,x,y,l,r,m,atk,a;
10 
11 void bsearch(LL a)
12 {
13     l=1,r=1e15;
14     while(l<r){
15         m=(l+r)/2;
16         atk=m/y+m/x;
17         if(atk>=a) r=m;
18         else l=m+1;
19     }
20     if(l%x==0&&l%y==0) printf("Both\n");
21     else if(l%x==0) printf("Vova\n");
22     else printf("Vanya\n");
23 }
24 
25 int main()
26 {
27     cin>>n>>x>>y;
28     for(i=1;i<=n;i++){
29         cin>>a;
30         bsearch(a);
31     }
32     return 0;    
33 }
View Code

 

 

话说这是做的第一次 cf诶----当时做A的时候发现是一个公式= =1+(1+2)+(1+2+3)---记得等于6分之多少来着---百度到之后,交上去= =居然过啦(好激动)

加油啊- ----  go--go--go

 

转载于:https://www.cnblogs.com/wuyuewoniu/p/4313646.html

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/4/38199.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息