hdu 计算机学院大学生程序设计竞赛(2015’12)The Magic Tower

The Magic Tower

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2335    Accepted Submission(s): 599


Problem Description
Like most of the RPG (role play game), “The Magic Tower” is a game about how a warrior saves the princess. 
After killing lots of monsters, the warrior has climbed up the top of the magic tower. There is a boss in front of him. The warrior must kill the boss to save the princess.
Now, the warrior wants you to tell him if he can save the princess.
 

Input
There are several test cases.
For each case, the first line is a character, “W” or “B”, indicating that who begins to attack first, ”W” for warrior and ”B” for boss. They attack each other in turn. 
The second line contains three integers, W_HP, W_ATK and W_DEF. (1<=W_HP<=10000, 0<=W_ATK, W_DEF<=65535), indicating warrior’s life point, attack value and defense value. 
The third line contains three integers, B_HP, B_ATK and B_DEF. (1<=B_HP<=10000, 0<=B_ATK, B_DEF<=65535), indicating boss’s life point, attack value and defense value. 

Note: warrior can make a damage of (W_ATK-B_DEF) to boss if (W_ATK-B_DEF) bigger than zero, otherwise no damage. Also, boss can make a damage of (B_ATK-W_DEF) to warrior if (B_ATK-W_DEF) bigger than zero, otherwise no damage. 
 

Output
For each case, if boss’s HP first turns to be smaller or equal than zero, please print ”Warrior wins”. Otherwise, please print “Warrior loses”. If warrior cannot kill the boss forever, please also print ”Warrior loses”.
 

Sample Input
  
  
W 100 1000 900 100 1000 900 B 100 1000 900 100 1000 900
 

Sample Output
  
  
Warrior wins Warrior loses


思路:注意当对boss伤害等于0时,默认为输。

模拟方法:

#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    char s;
    while(cin>>s)
    {
        int h[2],a[2],d[2];
        cin>>h[0]>>a[0]>>d[0];
        cin>>h[1]>>a[1]>>d[1];
        int wa=a[0]-d[1];
        int ba=a[1]-d[0];
       while(1)
       {
           if(s=='W')
           {
               if(wa<=0)
               {
                   cout<<"Warrior loses"<<endl;
                   break;
               }
               h[1]-=wa;
               if(h[1]<=0)
                   {
                       cout<<"Warrior wins"<<endl;
                       break;
                   }
               h[0]-=ba;
               if(h[0]<=0)
                   {
                       cout<<"Warrior loses"<<endl;
                       break;
                   }
           }
           else
           {
               if(wa<=0)
               {
                   cout<<"Warrior loses"<<endl;
                   break;
               }
               h[0]-=ba;
               if(h[0]<=0)
                   {
                       cout<<"Warrior loses"<<endl;
                       break;
                   }
               h[1]-=wa;
               if(h[1]<=0)
                   {
                       cout<<"Warrior wins"<<endl;
                       break;
                   }

           }
       }
    }
    return 0;
}

计算比较方法:

#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    char s;
    while(cin>>s)
    {
        int h[2],a[2],d[2];
        cin>>h[0]>>a[0]>>d[0];
        cin>>h[1]>>a[1]>>d[1];
        int wa=a[0]-d[1];
        int ba=a[1]-d[0];
        if(wa<=0)
        {
            cout<<"Warrior loses"<<endl;
            continue;
        }
        if(ba<=0)
        {
            cout<<"Warrior wins"<<endl;
            continue;
        }

            int t1=ceil(1.0*h[1]/wa);
            int t2=ceil(1.0*h[0]/ba);
            if(s=='W')
            {
                 if(t1<=t2)
                    cout<<"Warrior wins"<<endl;
                 else
                    cout<<"Warrior loses"<<endl;
            }
            else
            {    if(t2<=t1)
                    cout<<"Warrior loses"<<endl;
                 else
                    cout<<"Warrior wins"<<endl;
            }

    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值