zoukankan      html  css  js  c++  java
  • HDU2015校赛 The Magic Tower

    题意:两行分别是W和B的生命值,攻击值,防御值。

    如果W先,W的攻击值-B的防御值大于零则B生命值减去这么多,然后该B攻击。直到谁的生命值先小与等于零则攻击的人赢。

    输出写错了。。。。。

    错误代码

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstdlib>
     4 #include<stack>
     5 #include<queue>
     6 #include<vector>
     7 #include<map>
     8 #include<string.h>
     9 #include<algorithm>
    10 using namespace std;
    11 char c;
    12 int w[3],b[3];
    13 
    14 int main()
    15 {
    16     while(~scanf("%c",&c))
    17     {
    18         for(int i=0; i<3; i++)
    19             scanf("%d",&w[i]);
    20         for(int i=0; i<3; i++)
    21             scanf("%d",&b[i]);
    22         if(c=='W')
    23         {
    24             int ans=w[1]-b[2];
    25             if(ans<=0)
    26             {
    27                 printf("Warrior loses
    ");
    28                 continue;
    29             }
    30             while(b[0]>0&&w[0]>0)
    31             {
    32                 ans=w[1]-b[2];
    33                 if(ans>0)
    34                     b[0]-=ans;
    35                 if(b[0]<=0)
    36                 {
    37                     printf("Warrior wins
    ");
    38                     break;
    39                 }
    40                 else
    41                 {
    42                     ans=b[1]-w[2];
    43                     if(ans<=0)
    44                     {
    45                         printf("Warrior wins
    ");
    46                         break;
    47                     }
    48                     w[0]-=ans;
    49                     if(w[0]<=0)
    50                     {
    51                         printf("Warrior loses
    ");
    52                         break;
    53                     }
    54                 }
    55             }
    56         }
    57         else
    58         {
    59             int ans=b[1]-w[2];
    60             if(ans<=0)
    61             {
    62                 printf("Warrior wins
    ");
    63                 continue;
    64             }
    65             while(b[0]>0&&w[0]>0)
    66             {
    67                 ans=b[1]-w[2];
    68                 if(ans>0)
    69                     w[0]-=ans;
    70                 if(w[0]<=0)
    71                 {
    72                     printf("Warrior loses
    ");
    73                     break;
    74                 }
    75                 else
    76                 {
    77                     ans=w[1]-b[2];
    78                     if(ans<=0)
    79                     {
    80                         printf("Warrior loses
    ");
    81                         break;
    82                     }
    83                     b[0]-=ans;
    84                     if(b[0]<=0)
    85                     {
    86                         printf("Warrior wins
    ");
    87                         break;
    88                     }
    89                 }
    90             }
    91         }
    92     }
    93     return 0;
    94 }
    View Code

     AC代码

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstdlib>
     4 #include<stack>
     5 #include<queue>
     6 #include<vector>
     7 #include<map>
     8 #include<string.h>
     9 #include<algorithm>
    10 using namespace std;
    11 char c;
    12 int w[3],b[3];
    13 
    14 const int maxn=1e5+7;
    15 int main(){
    16     char str[3];
    17     while(~scanf("%s",str)){
    18         int a1,a2,a3,b1,b2,b3;
    19         scanf("%d%d%d%d%d%d",&a1,&a2,&a3,&b1,&b2,&b3);
    20         if(a2-b3<=0&&b2-a3<=0){
    21             printf("Warrior loses
    ");
    22             continue;
    23         }
    24         if(str[0]=='W'){
    25             int flag=0;
    26             while(a1>0&&b1>0){
    27                 if(flag==0){
    28                     b1-=(a2-b3);
    29                     flag=1;
    30                 }else{
    31                     a1-=(b2-a3);
    32                     flag=0;
    33                 }
    34             }
    35             if(a1<=0)printf("Warrior loses
    ");
    36             else printf("Warrior wins
    ");
    37         }else{
    38             int flag=0;
    39             while(a1>0&&b1>0){
    40                 if(flag==0){
    41                     a1-=(b2-a3);
    42                     flag=1;
    43                 }else{
    44                     b1-=(a2-b3);
    45                     flag=0;
    46                 }
    47             }
    48             if(a1<=0)printf("Warrior loses
    ");
    49             else printf("Warrior wins
    ");
    50         }
    51     }
    52     return 0;
    53 }
    View Code
  • 相关阅读:
    网页内容切换效果实现的15个jQuery插件
    【转】C#获取客户端及服务器端主机信息及其获取IP地址
    EnableViewState 属性
    Dictionary字典类使用范例
    AspNetPager分页控件官方网站
    [区别]APPlication,Session,Cookie,ViewState和Cache
    C#特性之数据类型
    WindowsPhone8.1 开发技巧
    关于在WP8.1中使用剪贴板的问题
    MVC中使用JQuery方式进行异步请求和使用自带方式进行异步请求
  • 原文地址:https://www.cnblogs.com/ITUPC/p/5078385.html
Copyright © 2011-2022 走看看