• 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. }

  • 相关阅读:
    学习C++的周期计划书
    【数据结构--二叉树】合并二叉树
    专题:链表常考题目汇总
    es查询响应结果中获取某些字段的值
    【数学建模学习笔记【集训十天】之第七天】
    SSH的在线音乐下载网站-JAVA【数据库设计、源码、开题报告】
    linux上系统磁盘满了的问题
    消息队列十连问
    收银系统源码-千呼新零售2.0【线上商城商品详情页细节优化】
    Kafka3.0.0版本——消费者(独立消费者消费某一个主题中某个分区数据案例__订阅分区)
  • 原文地址:https://blog.csdn.net/qq_63739337/article/details/126461672