Hust oj 1945 纸牌小游戏(模拟水题)
来源:互联网 发布:手机硬件检测软件 编辑:程序博客网 时间:2024/06/05 19:02
纸牌小游戏Time Limit: 1000 MSMemory Limit: 32768 KTotal Submit: 109(76 users)Total Accepted: 85(73 users)Rating: Special Judge: NoDescription
小A和小B在玩纸牌游戏,游戏的规则是:
小A使用栈,小B使用队列,给出一个长度为n的数列,从数列左边到数列右边依次入栈/入队,其中穿插m次出栈/出队操作。
最后,谁栈(队列)中的所剩数字的总和大,谁就是winner。(保证最终有一人胜出)
Input多组测试数据。
每组数据第一行有2个整数n,m(0<m<n<=1000)。
接下来是一个长度为n的整数序列(每个整数都在int范围内)。
接下来n+m行,每行都有下2个操作中的一个:
push 对于小A来说是入栈,对于小B来说是入队
pop 对于小A来说是出栈,对于小B来说是出队
Output每组测试数据输出一个整数,小A赢了的话输出1,否则输出2。
Sample Input5 33 5 9 4 2pushpoppushpushpoppushpushpopSample Output
1
模拟
#include<cstdio>#include<iostream>#include<algorithm>#include<stack>#include<queue>#include<cstring>using namespace std;const int Maxn = 1005;int a[Maxn];char str[5];int n,m;int main(){ while(~scanf("%d%d",&n,&m)) { stack<int>s; queue<int>q; int sum_1 = 0; int sum_2 = 0; int index = 0; for(int i=0;i<n;i++) { scanf("%d",&a[i]); } for(int i=0;i<n+m;i++) { scanf("%s",&str); if(strcmp(str,"push") == 0) { int temp = a[index++]; s.push(temp); sum_1 += temp; q.push(temp); sum_2 += temp; } else { sum_1 -= s.top(); s.pop(); sum_2 -= q.front(); q.pop(); } } if(sum_1 > sum_2) printf("1\n"); else printf("2\n"); }}
0 0
- Hust oj 1945 纸牌小游戏(模拟水题)
- Hust oj 1497 Death Knight Hero(字符串水题)
- Hust oj 1606 用户体验之帖子排序(模拟)
- Hust oj 1052 Darts(翻译题)
- Hust oj 2084(大数)
- Hust oj 1184 早起一水(简单贪心)
- nyoj1038纸牌游戏(模拟题)
- noip2002 均分纸牌 (模拟)
- Hust oj 2038 联系网络(MST)
- Hust oj 2234 土豪银行(贪心)
- Hust oj 1143 泉水(dfs)
- Hust oj 2113 Count(Map)
- Hust oj 1305 多边形(数学)
- Hust oj 1677 一个函数(栈)
- Hust oj 1039 修路(二分)
- Hust oj 1369 Buy Computers(水题)
- Hust oj 2121 你猜猜(水题)
- Hust oj 2005 排列问题(STL)
- jpg图片有2种格式 exif 和 jfif
- POJ1204 AC自动机
- 求码源
- WAMP虚拟主机(多站点)配置
- myeclipse报错:The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
- Hust oj 1945 纸牌小游戏(模拟水题)
- MySQL 命令行(1)
- Date的小练习
- 网络安全
- Github Pages
- 51nod 1279
- C++友元函数总结
- POJ 3090Visible Lattice Points
- 中序遍历二叉树