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.
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.
For each test case, you should print the answer in one line.
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
- 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
//如果小于第二种了,直接退出 - break;
- c++;//攻击次数+1
- n-=l;//生命值相应减少
- }
- if(n) c+=(n-1)/x+1;//剩下生命值全用第二种武器来攻击,向上取整
- printf("%lld\n",c);
- }
- return 0;
- }