codeforce 492 C D
2014-12-03 22:28
274 查看
C题贪心即可,但要用除法进行迭代,加法会超时。
D题我们把一秒分割为LCM(x,y)个单位,那么vanya没y个单位攻击一次,vova没x个单位攻击一次,明显先找到GCD(x,y),消去重复环节,然后暴力求解满足条件的时间,这里可以二分求解。
#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; }
相关文章推荐
- Codeforce 515 B . Drazil and His Happy Friends
- codeforce 277div2
- codeforce contest 713 #371 Div1 C
- Codeforces Round #278 (Div. 2) B. Candy Boxes [brute force+constructive algorithms]
- codeforce 贪心1
- Codeforce 721C(DAG上dp)
- codeforce 375_2_b_c
- codeforce 848A From Y to Y
- codeforce 796C Bank Hacking 智力题orz
- CodeForce 508C Anya and Ghosts (贪心+模拟)
- Codeforce 489E(dp+01分数规划)
- codeforce #165 div2
- codeforce #500场
- Codeforce Round #438 C.Bus(贪心)
- codeforce 382 div2 E —— 树状dp
- Codeforce 546 B. Soldier and Badges
- codeforce 743 D. Chloe and pleasant prizes (树形dp)
- codeforce #387 D. Winter Is Coming
- Codeforces GYM 100960B: ForceField 题解
- codeforce B Kefa and Company