[codeforces 1296D] Fight with Monsters 难在题意的理解+模+整除

[codeforces 1296D] Fight with Monsters 难在题意的理解+模+整除

总目录详见https://blog.csdn.net/mrcrack/article/details/103564004

在线测评地址https://codeforces.com/contest/1296/problem/D

ProblemLangVerdictTimeMemory
D - Fight with Monsters GNU C++11Accepted62 ms600 KB

若无此句解释,此题做不出啊。

Problem D. Fight with Monsters补充说明如下
*****
In each fight the first turn is always yours (it does not depend on who killed the last monster)

样例解释如下:

6 2 3 3
7 10 50 12 1 8
不用技策的情况如下
7  7%(2+3)=2  2-2=0;1分
10 10%(2+3)=0;0分      使用技策0+3=3,3-2=1,1-2=-1;需2次  (3+2-1)/2=2
50 50%(2+3)=0;0分      使用技策0+3=3,3-2=1,1-2=-1;需2次  (3+2-1)/2=2
12 12%(2+3)=2 2-2=0;1分
1 1%(2+3)=1 1-2=-1;1分
8 8%(2+3)=3 3-2=1 1-3=-2;0分      使用技策-2+3=1,1-2=-1;需1次 (1+2-1)/2=1

能用3次技策,故答案是5分

1 1 100 99
100
不用技策的情况如下
100%(1+100)=100,100-1=99,99-100=-1;0分   使用技策-1+100=99,(99+1-1)/1=99;需99次

7 4 2 1
1 3 5 4 2 7 6
不用技策的情况如下
1 1%(4+2)=1 1-4=-3;1分
3 3%(4+2)=3 3-4=-1;1分
5 5%(4+2)=5 5-4=1,1-2=-1;0分   使用技策-1+2=1 (1+4-1)/4=1;需1次
4 4%(4+2)=4 4-4=0;1分
2 2%(4+2)=2 2-4=-2;1分
7 7%(4+2)=1 1-4=-3;1分
6 6%(4+2)=0 ;0分   使用技策0+2=2 (2+4-1)/4=1;需1次

能用1次技策,故答案是6分

//样例理清,编程思路就有了

#include <cstdio>
#include <algorithm>
#define maxn 200010
int cnt[maxn],h;//cnt[]需要技策的数量
using namespace std;
int main(){
	int n,a,b,k,i,c,sum,tot;
	scanf("%d%d%d%d",&n,&a,&b,&k);
	for(i=1;i<=n;i++){
		scanf("%d",&h);
		c=h%(a+b);
		if(c==0)cnt[i]=(0+b+a-1)/a;//需技策
		else{//c>0讨论
			if(c<=a)cnt[i]=0;
			else cnt[i]=(c-a+a-1)/a;//需技策
		}
	}
	sort(cnt+1,cnt+1+n),sum=0,tot=0;//需技策的数量自小到大排序
	for(i=1;i<=n;i++){//统计需技策的数量
		if(sum+cnt[i]<=k)sum+=cnt[i],tot=i;
		else break;
	}
	printf("%d\n",tot);
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值