codeforce 492 C D

  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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值