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

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
 模拟题
理解题意就好
这里我先判断可以胜利和失败的情况‘
再讨论谁先攻击的情况
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x3fffffff
#define INF 0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define ULL unsigned long long
using namespace std;
int n;
int main ()
{
    string s;
    while(cin>>s)
    {
        int W_HP,W_ATK,W_DE;
        int B_HP,B_ATK,B_DE;
 
        int F;
        int D;
        cin>>W_HP>>W_ATK>>W_DE;
        cin>>B_HP>>B_ATK>>B_DE;
        int CA=W_ATK-B_DE;
        int CB=B_ATK-W_DE;
        if(W_ATK<=B_DE)
        {
            puts("Warrior loses");
        }
        else if(B_ATK<=W_DE&&W_ATK>B_DE)
        {
            puts("Warrior wins");
        }
        else if(W_ATK>B_DE&&B_ATK>W_DE)
        {
            if(s[0]=='W')
            {
                int S_1=B_HP;
                int S_2=W_HP;
                while(S_1>0&&S_2>0)
                {
                    S_1-=CA;
                    S_2-=CB;
                }
                if(S_1<=0)
                {
                    puts("Warrior wins");
                }
                else if(S_2<=0&&S_1>0)
                {
                    puts("Warrior loses");
                }
            }
            else
            {
                int S_1=B_HP;
                int S_2=W_HP;
                while(S_1>0&&S_2>0)
                {
                    S_2-=CB;
                    S_1-=CA;
                }
                if(S_2<=0)
                {
                    puts("Warrior loses");
                }
                else if(S_2>0&&S_1<=0)
                {
                    puts("Warrior wins");
                }
            }
        }
    }
    return 0;
}

  

posted @   樱花落舞  阅读(269)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示