链接:https://www.luogu.com.cn/problem/CF1932D
https://codeforces.com/problemset/problem/1932/D
总的来说,就是把每副牌分开存储,然后如果长度是奇数,那么就从万能牌中拿过来一张;如果是偶数就不需要
判断是否是impossible?
每组对2求余之后加起来,如果比万能牌长度长就impossible
题面:
代码:
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<sstream>
#include<string>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
#include<map>
#include<queue>
#include<limits.h>
#include<climits>
#include<fstream>
#include<stack>
#include<set>
typedef long long ll;
using namespace std;
const int N = 2e5 + 10;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
string menu = "CDHS";
int t;
cin >> t;
while (t--)
{
map<char, vector<int>>mp;
queue<string>qq;
int n; cin >> n;
char swin; cin >> swin;
string sk;
for (int i = 0; i < 2 * n; i++)
{
cin >> sk;
mp[sk[1]].push_back(sk[0] - '0');
}
int ptr = 0;
int twinow = 0;
for (map<char, vector<int>>::iterator it = mp.begin(); it != mp.end(); ++it)
{
sort(it->second.begin(), it->second.end());
}
for (map<char, vector<int>>::iterator it = mp.begin(); it != mp.end(); ++it)
{
if (it->first == swin)twinow = it->second.size();
else
{
if (it->second.size() % 2 == 1)ptr += 1;
}
}
if (twinow < ptr)cout << "IMPOSSIBLE" << endl;
else
{
for (int i = 0; i < 4; i++)
{
if (menu[i] != swin)
{
for (int j = 0; j < mp[menu[i]].size(); j++)
qq.push(string(to_string(mp[menu[i]][j]) + menu[i]));
if (mp[menu[i]].size() % 2)
{
qq.push(string(to_string(mp[swin][mp[swin].size() - 1]) + swin));
mp[swin].pop_back();
}
}
}
for (int i = 0; i < mp[swin].size(); ++i)
{
qq.push(string(to_string(mp[swin][i]) + swin));
}
while (!qq.empty())
{
cout << qq.front() << ' ';
qq.pop();
cout << qq.front() << endl;
qq.pop();
}
}
}
return 0;
}
标签:second,int,cin,sk,Game,mp,include,Card
From: https://www.cnblogs.com/zzzsacmblog/p/18141067