Problem Description
Japanese Mahjong is a four-player game. The game needs four people to sit around a desk and play with a set of Mahjong tiles. A set of Mahjong tiles contains four copies of the tiles described next:

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.)

 
Input
The input data begins with a integer T(1≤T≤20000). Next are T cases, each of which contains 13 tiles. The description of every tile is as above.
 
Output
For each cases, if there actually exists some tiles that can form a winning state with the 13 tiles given, print the number first and then print all those tiles in order as the description order of tiles above. Otherwise print a line "Nooten"(without quotation marks).
 
题目大意:给你十三张麻将牌,问你再加一张什么牌,可以胡。胡的方法:1、有一对眼,剩下的是顺子和三张相同的牌组成14张牌。2、有7个对子(4个相同的牌不能算两对,这个题目似乎没有说,就是看漏了这个条件WA了一个多小时……我就说怎么题目说两个我只看到一个呢……)。3、十三幺。
思路:枚举每一张牌,判断能否获胜。条件2、3特判即可。对于条件1,如果有某张字牌只有1张或4张,或有两个以上的字牌有2张,输出错误。然后枚举眼(对子),然后对每一种牌(万子、筒子、束子)分配从1~9循环,若某张牌 i 剩下3张或以上,那么把三张 i 作为三个相同的牌拿掉(如果这牌是能获胜的,那么枚举到 i ,i 前面的牌都已经被判断后拿掉了,那么如果 i 可以作为顺子被拿掉,那么 i+1 和 i+2 肯定都有3张或以上)。若小于三张,则把 i 、 i+1 、 i+2 拿掉。如果拿不掉则判断不能获胜。全部拿掉之后判断获胜。那些TLE的人肯定是姿势不对。
 
代码(265MS):
 #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)的更多相关文章

  1. 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) ...

  2. HDU 4433 locker 2012 Asia Tianjin Regional Contest 减少国家DP

    意甲冠军:给定的长度可达1000数的顺序,图像password像锁.可以上下滑动,同时会0-9周期. 每个操作.最多三个数字连续操作.现在给出的起始序列和靶序列,获得操作的最小数量,从起始序列与靶序列 ...

  3. HDU 4436 str2int(后缀自动机)(2012 Asia Tianjin Regional Contest)

    Problem Description In this problem, you are given several strings that contain only digits from '0' ...

  4. 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 ...

  5. 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 ...

  6. HDU 3721 Building Roads (2010 Asia Tianjin Regional Contest) - from lanshui_Yang

    感慨一下,区域赛的题目果然很费脑啊!!不过确实是一道不可多得的好题目!! 题目大意:给你一棵有n个节点的树,让你移动树中一条边的位置,即将这条边连接到任意两个顶点(边的大小不变),要求使得到的新树的直 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. c语言描述的二分插入排序法

    #include<stdio.h> #include<stdlib.h> //二分插入排序法 void BinsertSort(int a[],int n){ int low, ...

  2. ECMAScript 内置类型、对象和运算符

    原始值是以下内置类型 之一的成员:Undefined,Null,Boolean,Number,String: 对象是剩下的内置 类型 Object 的成员:函数是可调用对象 (callable obj ...

  3. vue2 自定义全局组件(Loading加载效果)

    vue2 自定义全局组件(Loading加载效果) github地址: https://github.com/ccyinghua/custom-global-component 一.构建项目 vue ...

  4. ATK-DataPortal 设计框架(三)

    边界清晰.服务自治.契约共享.基于策略的兼容性,是面向对向设计时四个基本原则,我们的应用可能分布在不同的环境之中,应用可能在同一服务器中,也可能在不同的网络环境中,保证框架的基类能在不同环境中仍然可用 ...

  5. 极光推送小结 - iOS

    此次即友盟分享小结(友盟分享小结 - iOS)之后对推送也进行了一版优化.此次分享内容依然基于已经成功集成 SDK 后 code 层级部分. 注:此次分享基于 SDK 3.1.0,若版本相差较大,仅供 ...

  6. iOS之报错“Cannot create __weak reference in file using manual reference counting”解决办法

    解决的办法:在Build Settings--------->Aplle LLVM8.0 - Language - Objectibe-C------------->Weak Refere ...

  7. 剑指offer js算法练习(1-10)

    1.二维数组中的查找       在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数, ...

  8. [Usaco2006 Mar]Mooo 奶牛的歌声(单调栈裸题)

    1657: [Usaco2006 Mar]Mooo 奶牛的歌声 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 961  Solved: 679[Submi ...

  9. P1247 取火柴游戏

    题目描述 输入k及k个整数n1,n2,-,nk,表示有k堆火柴棒,第i堆火柴棒的根数为ni:接着便是你和计算机取火柴棒的对弈游戏.取的规则如下:每次可以从一堆中取走若干根火柴,也可以一堆全部取走,但不 ...

  10. 【TOJ 3305】Hero In Maze II

    描述 500年前,Jesse是我国最卓越的剑客.他英俊潇洒,而且机智过人^_^.突然有一天,Jesse心爱的公主被魔王困在了一个巨大的迷宫中.Jesse听说这个消息已经是两天以后了,他急忙赶到迷宫,开 ...