【杭电2015年12月校赛I】【模拟水题】The Magic Tower 战士打魔王 能否打死它


The Magic Tower

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


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
 
#include<stdio.h>
#include<algorithm>
#include<ctype.h>
#include<string.h>
using namespace std;
int casenum,casei;
typedef long long LL;
const int N=105;
const int M=105*105;
int n,m;
struct A
{
    int x,y,z;
    bool operator < (const A& b)const
    {
        return z>b.z;
    }
}a[M];
int f[N];
int find(int x)
{
    if(f[x]==x)return x;
    f[x]=find(f[x]);
    return f[x];
}
char C;
int hp[2];
int att[2];
int def[2];
int hurt[2];
bool solve()
{
    hurt[0]=att[0]-def[1];
    hurt[1]=att[1]-def[0];
    if(hurt[0]<=0)return 0;
    if(hurt[1]<=0)return 1;
    int p=(C=='W'?0:1);
    while(1)
    {
        hp[p^1]-=hurt[p];
        if(hp[p^1]<=0)
        {
            return p==0;
        }
        p^=1;
    }
}
int main()
{
    while(~scanf(" %c",&C))
    {
        for(int i=0;i<2;++i)scanf("%d%d%d",&hp[i],&att[i],&def[i]);
        puts(solve()?"Warrior wins":"Warrior loses");
    }
    return 0;
}
/*
【题意】
又到了战士和魔王决斗的时刻了。
两人轮流攻击对方,生命值<=0为死亡。

告诉你谁先手,
告诉你战士和魔王的hp,attack,defence,
伤害=攻击者的attack-防御者的defence
(数值都是[1,10000]之间的整数)

让你输出战士是否能最终击杀魔王
可以输出Warrior wins
否则输出Warrior loses

【类型】
模拟 水题

【分析】
看代码就好了,那里逻辑很清楚。
注意,使用结构有序的写法,写起来也会超级方便哦。

【时间复杂度&&优化】
最坏情况下的时间复杂度为
O(hp[0]+hp[1])

*/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值