ZCMU--1515: ZDD vs. TIANKENG(C语言)

Description

There was a boy called ZDD, and he loved a girl whose name is SZD. They fell in love with each other deeply. But SZD was caught by TIANKENG. After finishing lots of hard work, finally ZDD found his lover and he needed to defeat TIANKENG so that they can get together. In order to defeat TIANKENG, ZDD had two weapons, the first one can decrease TIANKENG P% current HP, and the second one can make a fixed damage, in other world it can decrease TIANKENG X HP. If TIANKENG’s HP less than or equal to 0, then TIANKENG will be died. TIANKENG totally had N HP. ZDD wanted to know that the minimal number of shoot needed to kill TIANKENG because he was very eager to save his lover.

Input

The first line is an integer T, which indicates the number of test case.

For each test case, there are three integers N (1<=N<=1018), P (0<=P<=100), X (1<=X<=1018), which indicates TIANKENG’s totally HP, and the damage the weapons can make.

Output

For each test case, you should print the answer in one line.

Sample Input

4
100  50  10
100  100  99
100  10  50
100  1  1

Sample Output

5
1
2
100

HINT

For the first case: ZDD will first choose the first weapon and make 50 damage, then continue to use the first weapon and make 25 damage, then use the first weapon make 12 damage because the damage will round down to the nearest integer. Then use second weapon two times and make 20 damage, and TIANKENG will died. So the answer is 5.

注意点:感觉题目有点没说清楚,我们要把第一种武器伤害值取整才行,就生命值P用double类型,变量其他用long long类型

解析:我们可以发现如果当生命值P到一定数值,第一种武器伤害永远比第二种小,此后我们就一直用第二种武器即可,(n-1)/x+1向上取整就是剩下生命还需第二种武器补刀的次数。

#include <stdio.h>
int main()
{ 
	int t;
	long long c,n,x,l;
	double p;
	scanf("%d",&t);
	while(t--){
		c=0;//攻击次数 
		scanf("%lld%lf%lld",&n,&p,&x);
		p/=100;//p原来是百分比,转化一下小数好计算
		while(1){
			l=(long long)(p*n);//第一种武器伤害 
			if(l<x) //如果小于第二种了,直接退出 
				break;
			c++;//攻击次数+1 
			n-=l;//生命值相应减少 
		}
		if(n) c+=(n-1)/x+1;//剩下生命值全用第二种武器来攻击,向上取整 
		printf("%lld\n",c);
	}
	return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值