问题 B: B - 烦恼先生打麻将
时间限制: 1 Sec 内存限制: 256 MB
提交: 8 解决: 5
[提交][状态][讨论版]
题目描述
输入
6 6
Z D 1S 1S 9W 5W 2S 6S 2W 1S X B 2W 1W 7W 1T 6W 3T B BB 4S 3T 8W X 3T 4T
5T 9T 8T 2W B 5W 7W Z 9W B 9T 3S 7W 9S 8T 6W F 4T 9W 4T D 2T 2T 9T 7W 7S
4T 4S 3W N 9T BB 7S X 1S 5T 5S 5S 3W 7S 2S 8S 3T 8S 1W 1T 6T D 2S 8W 5W
5T 6T 4S 3W 9W 8W N 2W D 7S 1W 1T 1W 8W N 4W 5S 3S F BB 6T 4S Z 2T N 6W
5S 9S 7T 3S 8S 4W 9S 6S 6T 7T 5W 4W 8T 1T F 8S X 3W Z 3S 6W 9S 5T 7T 8T
F 2S 4W 6S 2T BB 6S 7T
Z D 1S 1S 9W 5W 2S 6S 2W 1S X B 2W 1W 7W 1T 6W 3T B BB 4S 3T 8W X 3T 4T
5T 9T 8T 2W B 5W 7W Z 9W B 9T 3S 7W 9S 8T 6W F 4T 9W 4T D 2T 2T 9T 7W 7S
4T 4S 3W N 9T BB 7S X 1S 5T 5S 5S 3W 7S 2S 8S 3T 8S 1W 1T 6T D 2S 8W 5W
5T 6T 4S 3W 9W 8W N 2W D 7S 1W 1T 1W 8W N 4W 5S 3S F BB 6T 4S Z 2T N 6W
5S 9S 7T 3S 8S 4W 9S 6S 6T 7T 5W 4W 8T 1T F 8S X 3W Z 3S 6W 9S 5T 7T 8T
F 2S 4W 6S 2T BB 6S 7T
输出
#1:
9T BB 7S X 6T D 2S 1W N 9S
4W 7T 6W 8T BB D 9W 2W 2W 6W
4S 3T 8T 7W
#2:
3T 8S 1W 1T 2W D 7S 1W 2T N
6W 5S 8S 6T 8T X 3S 7T 2T Z
1S 6S
#3:
3W 7S 2S 8S 3W 9W 8W N BB 6T
4S Z 3S 6S 4W 8S Z 5T 2S 6S
7T 1S 2S X
#4:
1S 5T 5S 5S 5W 5T 6T 4S 4W 5S
3S F 7T 5W F 3W F 4W 6S 5W
1S 1W 4T
样例输入
4 1
BB BB BB BB B B B B D 2W 2W 2W D D D 1W N X 1W 8W F 8W 8T 2T 4W 6T X 1S N N Z 1W 9T 1S 8T 1T 3T 2T 6S 9S 5S 5S 2W 3W X X 1W 1W 6W 2S 8S 4S 2S F 8S 4T 9W 5W Z 9T 1S 3W 6S 5W 4W 3S 6W 3S 4S 3T 5T 5S 8S 8W 4T 7W 5T Z 4T 7S 2T 3T 6T 7T 9S 4S 2S 7T 3S 2T 3T 9W F 3W 8T 9W 1T 3W 6T 7S 9T 4T 9S 7T N 5W 7T 1T 6S 8W 9T 8T 2S 8S 7W 5S 4W 6T 4S 9S 6S 3S 9W 6W Z 7S 1T 7W 5T 5W 1S 6W 4W 7W F 5T
样例输出
#1:
D
#2: #3:
N X 1W
#4:
1W Z 1W
提示
#include<iostream>
#include<string>
#include<cstring>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
queue<string>all_q;
queue<string>q[];
queue<string>chu[];
string pai;
int found;
int main()
{
while(!all_q.empty()) all_q.pop();
for(int i=;i<=;i++)
{
while(!q[i].empty())
q[i].pop();
while(!chu[i].empty())
chu[i].pop();
}
int a,b;
cin>>a>>b;
a=a+b;
int chu_pai=a%;
if(chu_pai==)
chu_pai=;
int huan=-;
if(chu_pai==)
huan=(a-)*;
else if(chu_pai==)
huan=+(a-)*;
else if(chu_pai==)
huan=+(a-)*;
else
huan=+(a-)*; for(int i=;i<=;i++)
{
cin>>pai;
all_q.push(pai);
}
//从2a-1开始摸牌
for(int i=;i<=huan;i++)
{
pai=all_q.front();
all_q.pop();
all_q.push(pai);
} //3论
int z=;
for(int i=;i<=;i++)
{
//从chu_pai开始,每个人摸4张
int lun=;
while(lun--)
{
for(int j=;j<=;j++)
{
pai=all_q.front();
all_q.pop();
q[z].push(pai);
}
z--;
if(z==)
z=;
}
}
//打牌
z=;
int is_peng=;
while(true)
{
//摸牌
if(!is_peng)
{
if(!all_q.empty())
{
pai=all_q.front();
all_q.pop();
q[z].push(pai);
}
else
break;
} //出牌
is_peng=;
if(q[z].empty())
break;
pai=q[z].front();
//cout<<z<<" "<<"chu_pai "<<pai<<endl;
q[z].pop();
chu[z].push(pai); found=z;
for(int i=;i<=;i++)
{
found=found+;
if(found==)
found=;
//cout<<"found "<<found<<endl;; int len=q[found].size();
int num=;
for(int j=;j<len;j++)
{
string his_card=q[found].front();
q[found].pop();
if(his_card==pai)
num++;
q[found].push(his_card);
}
/*if(found==4)
{
cout<<endl;
cout<<"pai "<<pai<<endl;
cout<<num<<endl;
}*/
if(num>=)
{
is_peng=;
for(int j=;j<len;j++)
{
string his_card=q[found].front();
q[found].pop();
//碰掉的牌出掉
if(his_card!=pai)
{
q[found].push(his_card);
}
}
z=found;
break;
}
}
if(!is_peng)
{
z--;
if(z==)
z=;
}
}
for(int i=;i<=;i++)
{
cout<<"#"<<i<<":"<<endl;
int num=;
if(chu[i].empty())
{
cout<<endl;
continue;
}
while(!chu[i].empty())
{
pai=chu[i].front();
chu[i].pop();
cout<<pai;
num++;
if(chu[i].empty()||num==)
{
num=;
cout<<endl;
}
else{
cout<<" ";
}
}
}
return ;
}