hdu 4461 第37届ACM/ICPC杭州赛区I题

本文介绍了一种算法,用于判断两人棋子游戏的胜负。通过计算每方棋子的总力量并考虑特定棋子的存在与否调整总力量,最终确定胜者。详细展示了算法实现的代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题意:给两个人一些棋子,每个棋子有其对应的power,若b没有或者c没有,或者二者都没有,那么他的total power就会减1,total power最少是1,求最后谁能赢

如果b或c出现的话,flag就标记为1,那么在判断的时候如果flag==0,就说明他们没出现过,那么就要-1,然后就wa了,必须要两个变量判断,不知道为什么

 

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<cmath>
 6 #include<queue>
 7 #include<map>
 8 using namespace std;
 9 #define MOD 1000000007
10 const int INF=0x3f3f3f3f;
11 const double eps=1e-5;
12 #define cl(a) memset(a,0,sizeof(a))
13 #define ts printf("*****\n");
14 const int MAXN=1005;
15 int n,m,tt;
16 int main()
17 {
18     int i,j,k;
19     #ifndef ONLINE_JUDGE
20     freopen("1.in","r",stdin);
21     #endif
22     scanf("%d",&tt);
23     while(tt--)
24     {
25         scanf("%d",&n);
26         char c[10];
27         int flag=0,ma=0,pao=0;
28         int sum1=0,sum2=0;
29         for(i=1;i<=n;i++)
30         {
31             scanf("%s",c);
32             if(c[0]=='A')  sum1+=16;
33             else if(c[0]=='B') sum1+=7,ma=true;
34             else if(c[0]=='C') sum1+=8,pao=true;
35             else if(c[0]=='D') sum1+=1;
36             else if(c[0]=='E') sum1+=1;
37             else if(c[0]=='F') sum1+=2;
38             else if(c[0]=='G') sum1+=3;
39         }
40         if((!ma)||(!pao))
41             if(sum1>1)sum1-=1;
42         flag=0;
43         ma=false,pao=false;
44         scanf("%d",&n);
45         for(i=1;i<=n;i++)
46         {
47             scanf("%s",c);
48             if(c[0]=='A')  sum2+=16;
49             else if(c[0]=='B') sum2+=7,ma=true;
50             else if(c[0]=='C') sum2+=8,pao=true;
51             else if(c[0]=='D') sum2+=1;
52             else if(c[0]=='E') sum2+=1;
53             else if(c[0]=='F') sum2+=2;
54             else if(c[0]=='G') sum2+=3;
55         }
56         if((!ma)||(!pao))
57             if(sum2>1)sum2-=1;
58         if(sum1==sum2)  printf("tie\n");
59         else if(sum1>sum2)  printf("red\n");
60         else printf("black\n");
61     }
62     return 0;
63 }

 

转载于:https://www.cnblogs.com/cnblogs321114287/p/4438683.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值