HDU 4431 Mahjong(枚举+模拟)(2012 Asia Tianjin Regional Contest)

One to nine Man, which we use 1m to 9m to represent;

One to nine Sou, which we use 1s to 9s to represent;

One to nine Pin, which we use 1p to 9p to represent;

Character tiles, which are:Ton, Nan, Sei, Pei, Haku, Hatsu, Chun, which we use 1c to 7c to represent.
A winning state means a set of 14 tiles that normally contains a pair of same tiles (which we call "eyes") and four melds. A meld is formed by either three same tiles(1m, 1m, 1m or 2c, 2c, 2c for example) or three continuous non-character tiles(1m, 2m, 3m or 5s, 6s, 7s for example).
However, there are two special winning states that are different with the description above, which are:
"Chii Toitsu", which means 7 different pairs of tiles;
"Kokushi Muso", which means a set of tiles that contains all these tiles: 1m, 9m, 1p, 9p, 1s, 9s and all 7 character tiles. And the rest tile should also be one of the 13 tiles above.
And the game starts with four players receiving 13 tiles. In each round every player must draw one tile from the deck one by one. If he reaches a winning state with these 14 tiles, he can say "Tsu Mo" and win the game. Otherwise he should discard one of his 14 tiles. And if the tile he throws out can form a winning state with the 13 tiles of any other player, the player can say "Ron" and win the game.
Now the question is, given the 13 tiles you have, does there exist any tiles that can form a winning state with your tiles?
(Notes: Some of the pictures and descriptions above come from Wikipedia.)
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
typedef long long LL; const int MAXN = ; struct TILES {
int P[MAXN], M[MAXN], S[MAXN], C[MAXN]; void init() {
#define CL(a) memset(a, 0, sizeof(a))
CL(P), CL(M), CL(S), CL(C);
} void read() {
char str[];
for(int i = ; i < ; ++i) {
scanf("%s", str);
switch(str[]) {
case 'p':++P[str[] - ''];break;
case 'm':++M[str[] - ''];break;
case 's':++S[str[] - ''];break;
case 'c':++C[str[] - ''];break;
}
}
} bool special_judge1() {
int cnt = ;
for(int i = ; i <= ; ++i) {
cnt += (M[i] == );
cnt += (S[i] == );
cnt += (P[i] == );
cnt += (C[i] == );
}
return cnt == ;
} bool special_judge2() {
bool eyes = false;
for(int i = ; i <= ; ++i) {
if(C[i] == || C[i] > ) return false;
if(C[i] == ) eyes = true;
}
if(M[] == || M[] > ) return false;
if(M[] == || M[] > ) return false;
if(S[] == || S[] > ) return false;
if(S[] == || S[] > ) return false;
if(P[] == || P[] > ) return false;
if(P[] == || P[] > ) return false;
if(M[] == || M[] == ) eyes = true;
if(S[] == || S[] == ) eyes = true;
if(P[] == || P[] == ) eyes = true;
return eyes;
} int UP[MAXN], UM[MAXN], US[MAXN]; bool isWin() {
int x;
for(int i = ; i <= ; ++i) {
if(P[i] - UP[i] >= ) UP[i] += ;
if(S[i] - US[i] >= ) US[i] += ;
if(M[i] - UM[i] >= ) UM[i] += ;
x = P[i] - UP[i];
if(x != ) {
UP[i] += x;
if((UP[i + ] += x) > P[i + ]) return false;
if((UP[i + ] += x) > P[i + ]) return false;
}
x = S[i] - US[i];
if(x != ) {
US[i] += x;
if((US[i + ] += x) > S[i + ]) return false;
if((US[i + ] += x) > S[i + ]) return false;
}
x = M[i] - UM[i];
if(x != ) {
UM[i] += x;
if((UM[i + ] += x) > M[i + ]) return false;
if((UM[i + ] += x) > M[i + ]) return false;
}
}
return true;
} bool judge() {
if(special_judge1() || special_judge2()) return true;
bool eyes = false;
for(int i = ; i <= ; ++i) {
if(C[i] == ) {
if(!eyes) eyes = true;
else return false;
}
if(C[i] == || C[i] == ) return false;
}
if(eyes) {
CL(UP), CL(UM), CL(US);
return isWin();
}
for(int i = ; i <= ; ++i) {
if(P[i] >= ) {
CL(UP), CL(UM), CL(US);
UP[i] = ;
if(isWin()) return true;
}
}
for(int i = ; i <= ; ++i) {
if(S[i] >= ) {
CL(UP), CL(UM), CL(US);
US[i] = ;
if(isWin()) return true;
}
}
for(int i = ; i <= ; ++i) {
if(M[i] >= ) {
CL(UP), CL(UM), CL(US);
UM[i] = ;
if(isWin()) return true;
}
}
return false;
} vector<int> ans2;
vector<char> ans1; void solve() {
ans1.clear();
ans2.clear();
for(int i = ; i <= ; ++i) {
++M[i];
if(M[i] <= && judge()) {
ans1.push_back('m');
ans2.push_back(i);
}
--M[i];
}
for(int i = ; i <= ; ++i) {
++S[i];
if(S[i] <= && judge()) {
ans1.push_back('s');
ans2.push_back(i);
}
--S[i];
}
for(int i = ; i <= ; ++i) {
++P[i];
if(P[i] <= && judge()) {
ans1.push_back('p');
ans2.push_back(i);
}
--P[i];
}
for(int i = ; i <= ; ++i) {
++C[i];
if(C[i] <= && judge()) {
ans1.push_back('c');
ans2.push_back(i);
}
--C[i];
}
} void print() {
int len = ans1.size();
if(len == ) {
puts("Nooten");
return ;
}
printf("%d", len);
for(int i = ; i < len; ++i)
printf(" %d%c", ans2[i], ans1[i]);
puts("");
}
} G; int main() {
int T;
scanf("%d", &T);
while(T--) {
G.init();
G.read();
G.solve();
G.print();
}
}
HDU 4431 Mahjong(枚举+模拟)(2012 Asia Tianjin Regional Contest)的更多相关文章
- HDU-4432-Sum of divisors ( 2012 Asia Tianjin Regional Contest )
Sum of divisors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4433 locker 2012 Asia Tianjin Regional Contest 减少国家DP
意甲冠军:给定的长度可达1000数的顺序,图像password像锁.可以上下滑动,同时会0-9周期. 每个操作.最多三个数字连续操作.现在给出的起始序列和靶序列,获得操作的最小数量,从起始序列与靶序列 ...
- HDU 4436 str2int(后缀自动机)(2012 Asia Tianjin Regional Contest)
Problem Description In this problem, you are given several strings that contain only digits from '0' ...
- HDU 4433 locker(DP)(2012 Asia Tianjin Regional Contest)
Problem Description A password locker with N digits, each digit can be rotated to 0-9 circularly.You ...
- HDU 4441 Queue Sequence(优先队列+Treap树)(2012 Asia Tianjin Regional Contest)
Problem Description There's a queue obeying the first in first out rule. Each time you can either pu ...
- HDU 3721 Building Roads (2010 Asia Tianjin Regional Contest) - from lanshui_Yang
感慨一下,区域赛的题目果然很费脑啊!!不过确实是一道不可多得的好题目!! 题目大意:给你一棵有n个节点的树,让你移动树中一条边的位置,即将这条边连接到任意两个顶点(边的大小不变),要求使得到的新树的直 ...
- HDU 3726 Graph and Queries(平衡二叉树)(2010 Asia Tianjin Regional Contest)
Description You are given an undirected graph with N vertexes and M edges. Every vertex in this grap ...
- HDU 4468 Spy(KMP+贪心)(2012 Asia Chengdu Regional Contest)
Description “Be subtle! Be subtle! And use your spies for every kind of business. ”― Sun Tzu“A spy w ...
- HDU 4467 Graph(图论+暴力)(2012 Asia Chengdu Regional Contest)
Description P. T. Tigris is a student currently studying graph theory. One day, when he was studying ...
随机推荐
- c语言描述的二分插入排序法
#include<stdio.h> #include<stdlib.h> //二分插入排序法 void BinsertSort(int a[],int n){ int low, ...
- ECMAScript 内置类型、对象和运算符
原始值是以下内置类型 之一的成员:Undefined,Null,Boolean,Number,String: 对象是剩下的内置 类型 Object 的成员:函数是可调用对象 (callable obj ...
- vue2 自定义全局组件(Loading加载效果)
vue2 自定义全局组件(Loading加载效果) github地址: https://github.com/ccyinghua/custom-global-component 一.构建项目 vue ...
- ATK-DataPortal 设计框架(三)
边界清晰.服务自治.契约共享.基于策略的兼容性,是面向对向设计时四个基本原则,我们的应用可能分布在不同的环境之中,应用可能在同一服务器中,也可能在不同的网络环境中,保证框架的基类能在不同环境中仍然可用 ...
- 极光推送小结 - iOS
此次即友盟分享小结(友盟分享小结 - iOS)之后对推送也进行了一版优化.此次分享内容依然基于已经成功集成 SDK 后 code 层级部分. 注:此次分享基于 SDK 3.1.0,若版本相差较大,仅供 ...
- iOS之报错“Cannot create __weak reference in file using manual reference counting”解决办法
解决的办法:在Build Settings--------->Aplle LLVM8.0 - Language - Objectibe-C------------->Weak Refere ...
- 剑指offer js算法练习(1-10)
1.二维数组中的查找 在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数, ...
- [Usaco2006 Mar]Mooo 奶牛的歌声(单调栈裸题)
1657: [Usaco2006 Mar]Mooo 奶牛的歌声 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 961 Solved: 679[Submi ...
- P1247 取火柴游戏
题目描述 输入k及k个整数n1,n2,-,nk,表示有k堆火柴棒,第i堆火柴棒的根数为ni:接着便是你和计算机取火柴棒的对弈游戏.取的规则如下:每次可以从一堆中取走若干根火柴,也可以一堆全部取走,但不 ...
- 【TOJ 3305】Hero In Maze II
描述 500年前,Jesse是我国最卓越的剑客.他英俊潇洒,而且机智过人^_^.突然有一天,Jesse心爱的公主被魔王困在了一个巨大的迷宫中.Jesse听说这个消息已经是两天以后了,他急忙赶到迷宫,开 ...