codeforce 492 C D
来源:互联网 发布:简述数据库的隔离级别 编辑:程序博客网 时间:2024/05/16 07:30
C题贪心即可,但要用除法进行迭代,加法会超时。
#include <iostream>#include <algorithm>#include <cstdio>using namespace std;struct exam{int g,d;}ex[100010];bool cmp(struct exam a,struct exam b){return a.d<b.d;}int main(){//freopen("in.txt","r",stdin);int n,r;long long now=0,tar,ave;cin>>n>>r>>ave;tar=ave*n;for(int i=1;i<=n;i++) {cin>>ex[i].g>>ex[i].d;now+=ex[i].g;}tar-=now;sort(ex+1,ex+n+1,cmp);int pos=1;long long ans=0;while(tar>0){while(ex[pos].g==r) pos++;if(tar>=(r-ex[pos].g)){ans+=(long long)(r-ex[pos].g)*ex[pos].d;tar-=r-ex[pos].g;pos++;}else{ans+=tar*ex[pos].d;break;}}cout<<ans<<endl;return 0;}
D题我们把一秒分割为LCM(x,y)个单位,那么vanya没y个单位攻击一次,vova没x个单位攻击一次,明显先找到GCD(x,y),消去重复环节,然后暴力求解满足条件的时间,这里可以二分求解。
#include <iostream>#include <cstdio>using namespace std;int gcd(int a,int b){int t=1;while(t){t=a%b;a=b;b=t;}return a;}int main(){//freopen("in.txt","r",stdin);long long n,x,y,sum;scanf("%I64d%I64d%I64d",&n,&x,&y);sum=x+y;for(int i=0;i<n;i++){long long t;scanf("%I64d",&t);long long temp=gcd(x,y);temp=x/temp*y;sum=temp/x+temp/y;t-=(t/sum)*sum;long long time=0,total=0,ty=1;long long l=0,r=temp;while(l<r){long long mid=(l+r)>>1;if((mid/x+mid/y)>=t) r=mid;else l=mid+1;}if(l%x==0&&l%y==0) cout<<"Both"<<endl;else if(l%y==0) cout<<"Vanya"<<endl;else cout<<"Vova"<<endl;}return 0;}
0 0
- codeforce 492 C D
- codeforce 237 C D
- Codeforce 445(A,B,C,D,E)
- Codeforce 621(A,B,C,D,E)
- CodeForce 492C(贪心)
- codeforce 11D
- codeforce 161 D
- codeforce 143D dp
- codeforce D. Password
- Codeforce 340D
- codeforce D. Password
- codeforce D. Password
- (10D)codeforce
- Codeforce 148D
- Codeforce 567D
- codeforce 590d
- codeforce 589 D. Boulevard
- codeforce 241div2 D
- oracle/SCN
- 原题忘了
- NOJ1030ACM程序设计之马拉松竞赛
- 代码布局relativeLayout
- 用js在button上显示 倒计时
- codeforce 492 C D
- 第十五周项目3——在OJ上玩指针(2)
- Evacuation Plan - POJ 3963 dp滚动数组
- NOJ上的大数相加
- 选购电脑填补知识
- winDbg定位异常崩溃和线程死锁三步骤
- 一次遍历, 查找不定长链表中点
- NOJ1004线性表操作
- 正则表达式学习笔记(三)