• 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向上取整就是剩下生命还需第二种武器补刀的次数。

    1. #include
    2. int main()
    3. {
    4. int t;
    5. long long c,n,x,l;
    6. double p;
    7. scanf("%d",&t);
    8. while(t--){
    9. c=0;//攻击次数
    10. scanf("%lld%lf%lld",&n,&p,&x);
    11. p/=100;//p原来是百分比,转化一下小数好计算
    12. while(1){
    13. l=(long long)(p*n);//第一种武器伤害
    14. if(l//如果小于第二种了,直接退出
    15. break;
    16. c++;//攻击次数+1
    17. n-=l;//生命值相应减少
    18. }
    19. if(n) c+=(n-1)/x+1;//剩下生命值全用第二种武器来攻击,向上取整
    20. printf("%lld\n",c);
    21. }
    22. return 0;
    23. }

  • 相关阅读:
    SpringBoot 22 Swagger配置扫描接口和开关、过滤url、根据环境决定使用
    【C++】模板初阶 | STL简介
    AI自己写代码让智能体进化!OpenAI的大模型有“人类思想”那味了
    linux驱动开发学习001:概述
    Mysql003:基础查询
    第37章_瑞萨MCU零基础入门系列教程之DAC数模转换模块
    去掉macOS终端命令行前的(base)
    Java集合面试题整理(超详细)
    C++项目中mysql的环境配置与连接
    NVIDIA NCC​L 源码学习(三)- 机器内拓扑分析
  • 原文地址:https://blog.csdn.net/qq_63739337/article/details/126461672