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

来源:互联网 发布:mac 查找软件安装路径 编辑:程序博客网 时间:2024/05/24 04:45

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
W100 1000 900100 1000 900B100 1000 900100 1000 900
 

Sample Output
Warrior winsWarrior 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;}



0 0
原创粉丝点击