【杭电2015年12月校赛I】【模拟水题】The Magic Tower 战士打魔王 能否打死它
来源:互联网 发布:手机录音剪辑软件 编辑:程序博客网 时间:2024/06/03 01:23
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.
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.
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
#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
- 【杭电2015年12月校赛I】【模拟水题】The Magic Tower 战士打魔王 能否打死它
- 2015’12杭电校赛1009 The Magic Tower(水题快上!)
- 计算机学院大学生程序设计竞赛(2015’12)The Magic Tower(水~~~)
- The Magic Tower
- hdu 计算机学院大学生程序设计竞赛(2015’12)The Magic Tower
- 计算机学院大学生程序设计竞赛(2015’12)The Magic Tower
- 计算机学院大学生程序设计竞赛(2015’12)1009 The Magic Tower
- 【杭电2015年12月校赛A】【水题 暴力】The Country List 多少个名字与其它名字more than 2位置字符相同
- HDU The Magic Tower(2015.12.26训练 杭电校赛)
- 【杭电oj】1443 - Joseph(模拟,打表)
- I smell magic in the air
- 个人赛&cf G题:The Tower of Evil 模拟&数学
- CodeForces--606A --Magic Spheres(模拟水题)
- (fzu)Problem I Magic(模拟+后缀匹配)
- 经典好题!杭电OJ--Ignatius and the Princess I
- 杭电OJ 1026:Ignatius and the Princess I
- 杭电acm1026 Ignatius and the Princess I
- 【杭电-oj】-2039-能否构成三角形
- ext2、ext3与ext4的区别
- outlook 2013常见设置以及遇到的问题
- 关系模型中的术语
- maven根据profile中定义的环境变量打包的设置详解
- Swift与OC混编
- 【杭电2015年12月校赛I】【模拟水题】The Magic Tower 战士打魔王 能否打死它
- Win7印象笔记快捷键修改及使用
- animation - 6
- 【Linux运维入门】Linux环境安装配置Maven
- lunix常用命令
- xStream完美转换XML、JSON
- 实现守护进程
- android调用系统相机拍照并保存在本地
- 微信公众号素材管理新增其他类型永久素材