QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#390878#4777. TichuI_Love_Sonechka#AC ✓220ms3752kbC++172.2kb2024-04-16 00:52:412024-04-16 00:52:41

Judging History

你现在查看的是最新测评结果

  • [2024-04-16 00:52:41]
  • 评测
  • 测评结果:AC
  • 用时:220ms
  • 内存:3752kb
  • [2024-04-16 00:52:41]
  • 提交

answer

#include <bits/stdc++.h>
#include <math.h>
			
using namespace std;

// c++ short types
#define Int long long
#define vt vector

string values = "23456789TJQKA", suits = "hdcs";

array<int, 2> read() {
	string s; cin >> s;
	array<int, 2> res;
	for(int i = 0; i < (int)values.size(); ++i) if(s[0] == values[i]) {
		res[0] = i;
	}
	for(int i = 0; i < (int)suits.size(); ++i) if(s[1] == suits[i]) {
		res[1] = i;
	}
	return res;
}

void solver() {
	vt<array<int, 2>> a(13);
	for(auto &x: a) {
		x = read();
	}
	int n = a.size();
	vt<int> masks(1 << n, n), from(1<<n, -1);
	masks[0] = 0;
	for(int i = 1; i < (1<<n); ++i) {
		vt<int> ids;
		for(int j = 0; j < n; ++j) if(i >> j & 1) {
			ids.push_back(j);
		}
		vt<int> vals;
		for(int id: ids) {
			vals.push_back(a[id][0]);
		}
		sort(vals.begin(), vals.end());
		bool flag = false;
		if(ids.size() <= 4) {
			bool fl = true;
			for(auto id: ids) {
				fl = fl && a[ids[0]][0] == a[id][0];
			}
			flag = fl || flag;
		} else if(ids.size() == 5) {
			flag = vals[0] != vals[4] && (vals[0] == vals[2] && vals[3] == vals[4] || vals[0] == vals[1] && vals[2] == vals[4]);
		}
		if(ids.size() >= 5) {
			bool fl = 1;
			for(int j = 0; j + 1 < vals.size(); ++j) {
				fl = fl && vals[j+1]-vals[j] == 1;
			}
			flag = flag || fl;
		}
		if(flag) {
			masks[i] = 1;
		}
	}
	for(int i = 1; i < (int)masks.size(); ++i) {
		for(int j = i; j > 0; j = i & (j-1)) {
			if(masks[j] + masks[i ^ j] < masks[i]) {
				masks[i] = masks[j] + masks[i ^ j];
				from[i] = j;
			}
	}
	}
	vt<vt<int>> res;
	auto rec = [&](auto self, int mask) -> void {
		if(masks[mask] == 0) {
			return ;
		}
		if(masks[mask] == 1) {
			res.push_back({});
			for(int i = 0; i < n; ++i) if(mask >> i & 1) {
				res.back().push_back(i);
			}
			return ;
		}
		self(self, from[mask]);
		self(self, mask ^ from[mask]);
	};
	rec(rec, (1<<n)-1);
	cout << res.size() << "\n";
	for(auto v: res) {
		for(auto i: v) {
			cout << values[a[i][0]] << suits[a[i][1]] << " ";
		}
		cout << "\n";
	}
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	int tt = 1;
	cin >> tt;
	for(int t = 0; t < tt; ++t) {
    solver();
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 7ms
memory: 3624kb

input:

2
2h 3c 4d 5d 6s Th Qc Qs Ad Tc Ts 9c 9d
2h 3h 4h 5h 6d 7s 8h 8d 8c 8s 9c Td Js

output:

4
Th Tc Ts 9c 9d 
Ad 
Qc Qs 
2h 3c 4d 5d 6s 
2
2h 3h 4h 5h 6d 7s 8s 9c Td Js 
8h 8d 8c 

result:

ok correct (2 test cases)

Test #2:

score: 0
Accepted
time: 220ms
memory: 3752kb

input:

63
2h 3c 4d 5d 6s Th Qc Qs Ad Tc Ts 9c 9d
2h 3h 4h 5h 6d 7s 8h 8d 8c 8s 9c Td Js
2h 2d 2c 2s 4s 4d 4c Qh Qs Qc Ts Js Ac
5d 5c 7d 5s 3s 3c Qh 3d Qc Ts 5h Js Qs
2s 3h 4d 5d 6d 7s 8s 9s Tc Jd Qc Kc As
2s 3h 4d 5d 6d 7s 8s 9s Tc Jd Qc Kc 8c
2s 3h 4d 5d 6d 7s 8s 9s Tc Jd Qc 8c 7h
3h 4d 5d 6d 7s 8s 9s Tc ...

output:

4
Th Tc Ts 9c 9d 
Ad 
Qc Qs 
2h 3c 4d 5d 6s 
2
2h 3h 4h 5h 6d 7s 8s 9c Td Js 
8h 8d 8c 
5
Ac 
Js 
Ts 
2c 2s Qh Qs Qc 
2h 2d 4s 4d 4c 
5
5s Qh Qc 5h Qs 
Js 
Ts 
5d 5c 3s 3c 3d 
7d 
1
2s 3h 4d 5d 6d 7s 8s 9s Tc Jd Qc Kc As 
2
2s 3h 4d 5d 6d 7s 9s Tc Jd Qc Kc 8c 
8s 
2
9s Tc Jd Qc 8c 7h 
2s 3h 4d 5d 6d...

result:

ok correct (63 test cases)