zoukankan      html  css  js  c++  java
  • 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
     模拟题
    理解题意就好
    这里我先判断可以胜利和失败的情况‘
    再讨论谁先攻击的情况
    #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;
    }
    

      

  • 相关阅读:
    11gR2 RAC手动添加节点数据库实例 转
    Oracle 11g rac添加删除集群数据库
    11gR2RAC更换CRS磁盘组文档
    Java堆、栈和常量池
    牛人博客
    异常的定义和分类
    java中Proxy(代理与动态代理)
    详解java定时任务
    世界上最大的风不是台风,而是枕边风
    tomcat 日志catalina.out 按天自动分割 设定时任务定时清除
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/5087107.html
Copyright © 2011-2022 走看看