Description
唬牌是一种扑克游戏,包含A,2,3,4,5,6,7,8,9,10,J,Q,K各四张。
有四个玩家参与这个游戏。
每一位玩家在游戏开始时都会有随机的13张牌。
在桌子上没有牌时,玩家选择任意一个点数x和一个数字y(y小于等于手中牌数且至少为一),并打出任意y张牌,并将这y张牌的背面朝上放在桌上,声称"这是y张x牌"。
当桌子上有牌时,玩家可以选择两种操作
(1)选择一个数字z,并打出任意z张牌,声称"这是z张x牌",注意:x与上一位打出牌的玩家所选的点数相同。
(2)质疑上一位玩家,然后他将翻转上一位玩家打出的牌,并检查上一位玩家的陈述是否正确。
若质疑成功(上一位玩家的陈述与其打出的牌不符),则被质疑者拿走桌上所有的牌。
若质疑失败,则质疑者拿走桌上所有的牌。
当一个玩家选择质疑,并且在某位玩家拿了桌上所有的牌之后,如果有玩家手里没有牌,那么我们就说这个玩家赢了这场游戏。
为了简化,这次您需要编写一个程序来模拟游戏过程,在程序中,用1代表A,11代表J,12代表Q,13代表K

Input

有t组样例

对于每一个样例

首先是4行,第i行包含13个数字,第i位玩家手中的牌
然后一行包含一个整数m (2 <=m <= 20),表示游戏回合数。接下来的m行,每一行都是以下格式之一:
1. ”S x y a1 a2 ……ay“,意思是当前的玩家出牌a1, a2,..., ay,并声明“这些是y张x牌”。
2. “! y a1 a2…,ay”,意思是当前的玩家选择不质疑,并打出y张牌a1, a2...
ay,并声明“这些是y张牌x”,其中x保持不变(仍是上次说明的x)
3. “?“,表示当前玩家选择提出问题。 测试保证所有操作都是合法的。在这个过程中,没有人会赢。
Output

对于每一个样例

输出四行,第i位玩家在m回合后,非递减顺序牌。

每一行末尾有空格

末尾包含换行

Sample Input

1

8 12 12 9 3 10 13 11 12 4 10 2 1
2 10 13 9 9 3 12 4 6 13 3 11 13
11 1 10 5 7 4 5 6 7 7 5 6 9
4 1 11 2 1 8 8 3 2 6 5 8 7
5
S 1 2 2 3
! 1 2
! 1 1
! 2 1 1
?
Sample Output
1 1 1 1 2 2 3 4 8 9 10 10 11 12 12 12 13
3 3 4 6 9 9 10 11 12 13 13 13
4 5 5 5 6 6 7 7 7 9 10 11
2 2 3 4 5 6 7 8 8 8 11
 
 

分析,纯正暴力枚举,然后超时了,下面是超时代码,但是结果应该正确 
#include<iostream> #include <vector> #include <algorithm> using namespace std;
int main(){ int t,k,m,num=1,x,y; char temp; int temp1=0; int temp2;
vector<int>p;vector<int>p1;vector<int>p2;vector<int>p3;vector<int>p4;
scanf("%d",&t); while(t--){ for(int i=0;i<13;i++){ scanf("%d",&k);
p1.push_back(k); } for(int i=0;i<13;i++){ scanf("%d",&k); p2.push_back(k); }
for(int i=0;i<13;i++){ scanf("%d",&k); p3.push_back(k); } for(int
i=0;i<13;i++){ scanf("%d",&k); p4.push_back(k); }
sort(p1.begin(),p1.end());sort(p2.begin(),p2.end());
sort(p3.begin(),p3.end());sort(p4.begin(),p4.end()); scanf("%d",&m); while(m--)
{ getchar(); temp=getchar(); if ((char)temp=='S'&&num%4==1) { scanf("%d%d", &x,
&y); for (int i = 0; i < y; i++) { scanf("%d", &k); p.push_back(k); temp2 =
(lower_bound(p1.begin(), p1.end(), k) - p1.begin()); p1.erase(p1.begin() +
temp2); } num++; } else if (temp=='!'&&num % 4 == 1) { scanf("%d",&y); for (int
i = 0; i < y; i++) { scanf("%d", &k); p.push_back(k); temp2 =
(lower_bound(p1.begin(), p1.end(), k) - p1.begin()); p1.erase(p1.begin() +
temp2); } num++; } else if (temp=='?'&&num % 4 == 1) { for (auto it = p.end() -
1; it >= p.end() - y; it--) { if (*it == x) { temp1++; } } if (temp1 == y) {
for (auto it = p.begin(); it < p.end(); it++) { p1.push_back(*it); } } if
(temp1 != y) { for (auto it = p.begin(); it < p.end(); it++){
p4.push_back(*it); } } sort(p1.begin(),p1.end());sort(p2.begin(),p2.end());
sort(p3.begin(),p3.end());sort(p4.begin(),p4.end()); p.clear(); num++; temp1=0;
} else if (temp=='s'&&num%4==2) { scanf("%d%d", &x, &y); for (int i = 0; i < y;
i++) { scanf("%d", &k); p.push_back(k); temp2 = (lower_bound(p2.begin(),
p2.end(), k) - p2.begin()); p2.erase(p2.begin() + temp2); } num++; } else if
(temp=='!'&&num % 4 == 2) { scanf("%d",&y); for (int i = 0; i < y; i++) {
scanf("%d", &k); p.push_back(k); temp2 = (lower_bound(p2.begin(), p2.end(), k)
- p2.begin()); p2.erase(p2.begin() + temp2); } num++; } else if (temp=='?'&&num
% 4 == 2) { for (auto it = p.end() - 1; it >= p.end() - y; it--) { if (*it ==
x) { temp1++; } } if (temp1 == y) { for (auto it = p.begin(); it < p.end();
it++) { p2.push_back(*it); } } if (temp1 != y) { for (auto it = p.begin(); it <
p.end(); it++){ p1.push_back(*it); } }
sort(p1.begin(),p1.end());sort(p2.begin(),p2.end());
sort(p3.begin(),p3.end());sort(p4.begin(),p4.end()); p.clear(); num++; temp1=0;
} else if (temp=='s'&&num%4==3) { scanf("%d%d", &x, &y); for (int i = 0; i < y;
i++) { scanf("%d", &k); p.push_back(k); temp2 = (lower_bound(p3.begin(),
p3.end(), k) - p3.begin()); p3.erase(p3.begin() + temp2); } num++; } else if
(temp=='!'&&num % 4 == 3) { scanf("%d",&y); for (int i = 0; i < y; i++) {
scanf("%d", &k); p.push_back(k); temp2 = (lower_bound(p3.begin(), p3.end(), k)
- p3.begin()); p3.erase(p3.begin() + temp2); } num++; } else if (temp=='?'&&num
% 4 == 3) { for (auto it = p.end() - 1; it >= p.end() - y; it--) { if (*it ==
x) { temp1++; } } if (temp1 == y) { for (auto it = p.begin(); it < p.end();
it++) { p3.push_back(*it); } } if (temp1 != y) { for (auto it = p.begin(); it <
p.end(); it++){ p2.push_back(*it); } }
sort(p1.begin(),p1.end());sort(p2.begin(),p2.end());
sort(p3.begin(),p3.end());sort(p4.begin(),p4.end()); p.clear(); num++; temp1=0;
} else if (temp=='s'&&num%4==0) { scanf("%d%d", &x, &y); for (int i = 0; i < y;
i++) { scanf("%d", &k); p.push_back(k); temp2 = (lower_bound(p4.begin(),
p4.end(), k) - p4.begin()); p4.erase(p4.begin() + temp2); } num++; } else if
(temp=='!'&&num % 4 == 0) { scanf("%d",&y); for (int i = 0; i < y; i++) {
scanf("%d", &k); p.push_back(k); temp2 = (lower_bound(p4.begin(), p4.end(), k)
- p4.begin()); p4.erase(p4.begin() + temp2); } num++; } else if (temp=='?'&&num
% 4 == 0) { for (auto it = p.end() - 1; it >= p.end() - y; it--) { if (*it ==
x) { temp1++; } } if (temp1 == y) { for (auto it = p.begin(); it < p.end();
it++) { p4.push_back(*it); } } if (temp1 != y) { for (auto it = p.begin(); it <
p.end(); it++){ p3.push_back(*it); } }
sort(p1.begin(),p1.end());sort(p2.begin(),p2.end());
sort(p3.begin(),p3.end());sort(p4.begin(),p4.end()); p.clear(); num++; temp1=0;
} } for(auto it=p1.begin();it<p1.end();it++){ if(it==p1.begin())
printf("%d",*it); else printf(" %d",*it); } printf("\n"); for(auto
it=p2.begin();it<p2.end();it++){ if(it==p2.begin()) printf("%d",*it); else
printf(" %d",*it); } printf("\n"); for(auto it=p3.begin();it<p3.end();it++){
if(it==p3.begin()) printf("%d",*it); else printf(" %d",*it); } printf("\n");
for(auto it=p4.begin();it<p4.end();it++){ if(it==p4.begin()) printf("%d",*it);
else printf(" %d",*it); } printf("\n"); } }
 

肝了四个小时,超时了 cnm 

技术
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信