Problem C
Chinese Mahjong
Mahjong () is a game of Chinese origin usually played by four persons with tiles resembling dominoes and bearing various designs,
which are drawn and discarded until one player wins with a hand of four combinations of three tiles each and a pair of matching tiles.
A set of Mahjong tiles will usually differ from place to place. It usually has at least 136 tiles, most commonly 144, although sets originating from America or Japan will have more. The 136-tile Mahjong
includes:
Dots:named as each tile consists of a number of circles. Each circle is said to represent copper (tong) coins with a square hole in the middle. In this problem, they're represented by
1T, 2T, 3T, 4T, 5T, 6T, 7T, 8T and 9T.
Bams:named as each tile (except the 1 Bamboo) consists of a number of bamboo sticks. Each stick is said to represent a string (suo) that holds a hundred coins. In this problem, they're
represented by 1S, 2S, 3S, 4S, 5S, 6S, 7S, 8S and 9S.
Craks:named as each tile represents ten thousand (wan) coins, or one hundred strings of one hundred coins. In this problem, they're represented by 1W, 2W, 3W, 4W, 5W, 6W, 7W, 8W and
9W.
Wind tiles:East, South, West, and North. In this problem, they're represented by DONG, NAN, XI, BEI.
Dragon tiles:red, green, and white. The term dragon tile is a western convention introduced by Joseph Park Babcock in his 1920 book introducing Mahjong to America. Originally, these
tiles are said to have something to do with the Chinese Imperial Examination. The red tile means you pass the examination and thus will be appointed a government official. The green tile means, consequently you will become financially well off. The white tile
(a clean board) means since you are now doing well you should act like a good, incorrupt official. In this problem, they're represented by ZHONG, FA, BAI.
There are 9*3+4+3=34 kinds, with exactly 4 tiles of each kind, so there are 136 tiles in total.
To who may be interested, the 144-tile Mahjong also includes:
Flower tiles:
typically optional components to a set of mahjong tiles, often contain artwork on their tiles. There are exactly one tile of each kind, so 136+8=144 tiles in total. In this problem, we don��t consider
these tiles.
Chinese Mahjong is very complicated. However, we only need to know very few of the rules in order to solve this problem. Ameldis a certain set of tiles in one's hand. There are three
kinds of melds you need to know (to who knows Mahjong already, kong is not considered):
Pong:A set of three identical titles. Example:;.
Chow:A set of three suited tiles in sequence. All three tiles must be of the same suites. Sequences of higher length are not permissible (unless it forms more than one meld). Obviously,
wind tiles and dragon tiles can never be involved in chows. Example:;.
Eye:The pair, while not a meld, is the final component to the standard hand. It consists of any two identical tiles.
A player wins the round by creating a standard mahjong hand. That means, the hand consists of an eye and several (possible zero) pongs and chows. Note that each title can be involved in exactly one eye/pong/chow.
When a hand is one tile short of wining, the hand is said to be a ready hand, or more figuratively, 'on the pot'. The player holding a ready hand is said to be waiting for certain tiles. For example
is waiting for,and.
To who knows more about Mahjong: don't consider special winning hands such as ''.
Input
The input consists of at most 50 test cases. Each case consists of 13 tiles in a single line. The hand is legal (e.g. no invalid tiles, exactly 13 tiles). The last case is followed by a single zero,
which should not be processed.
Output
For each test case, print the case number and a list of waiting tiles sorted in the order appeared in the problem description (1T~9T, 1S~9S, 1W~9W, DONG, NAN, XI, BEI, ZHONG, FA, BAI). Each waiting
tile should be appeared exactly once. If the hand is not ready, print a message 'Not ready' without quotes.
Sample Input
1S 1S 2S 2S 2S 3S 3S 3S 7S 8S 9S FA FA
1S 2S 3S 4S 5S 6S 7S 8S 9S 1T 3T 5T 7T
0
Output for the Sample Input
Case 1: 1S 4S FA
Case 2: Not ready
题意:麻将,给一副牌,问哪几张牌可以听。
思路:暴力枚举。。
代码:
#include <stdio.h>
#include <string.h>
const char *mj[] = {
"1T", "2T", "3T", "4T", "5T", "6T", "7T", "8T", "9T",
"1S", "2S", "3S", "4S", "5S", "6S", "7S", "8S", "9S",
"1W", "2W", "3W", "4W", "5W", "6W", "7W", "8W", "9W",
"DONG", "NAN", "XI", "BEI",
"ZHONG", "FA", "BAI"
};
int c[34], C[13];
char s[100];
int find(char *s) {
for (int i = 0; i < 34; i ++)
if (strcmp(mj[i], s) == 0)
return i;
return -1;
}
void init() {
C[0] = find(s);
for (int i = 1; i < 13; i ++) {
scanf("%s", s);
C[i] = find(s);
}
}
bool dfs(int d) {
if (d == 4) return true;
for (int i = 0; i < 34; i ++) {
if (c[i] >= 3) {
c[i] -= 3;
if (dfs(d + 1)) return true;
c[i] += 3;
}
}
for (int i = 0; i <= 24; i++) {
if (i % 9 <= 6 && c[i] >= 1 && c[i + 1] >= 1 && c[i + 2] >= 1) {
c[i]--; c[i + 1]--; c[i + 2]--;
if (dfs(d + 1)) return true;
c[i] ++; c[i + 1]++; c[i + 2]++;
}
}
return false;
}
bool judge() {
for (int i = 0; i < 34; i ++) {
if (c[i] < 2) continue;
c[i] -= 2;
if (dfs(0)) return true;
c[i] += 2;
}
return false;
}
void solve() {
int flag = 0;
for (int i = 0; i < 34; i ++) {
memset(c, 0, sizeof(c));
for (int j = 0; j < 13; j ++)
c[C[j]]++;
if (c[i] >= 4) continue;
c[i] ++;
if (judge()) {
flag = 1;
printf(" %s", mj[i]);
}
c[i] --;
}
if (flag) printf("\n");
else printf(" Not ready\n");
}
int main() {
int cas = 0;
while (~scanf("%s", s) && s[0] != '0') {
init();
printf("Case %d:", ++cas);
solve();
}
return 0;
}
分享到:
相关推荐
中文麻将 自述文件:| 本届中国标准麻将比赛由北京大学AILab和潍坊宇(北京)科技有限公司主办。 单击导航到Botzone上的麻将比赛。 是一个通用的在线多代理游戏AI平台,旨在通过将游戏AI应用于代理并相互竞争来...
Mahjong
VC做的麻将游戏,界面美观,功能完善,全部分享给大家,希望喜欢!
日本麻将助手 主要功能 对战时自动分析手牌,综合进张、打点等,给出推荐舍牌 有人立直或多副露时,显示各张牌的危险度 记录他家手切摸切 助手带你看牌谱,推荐每一打的进攻和防守选择 支持四人麻将和三人麻将 ...
在 Unix/Linux 系统上,进入 mahjong 目录,键入 make 命令,如果一切顺利的话,将生成 mj 可执行文件,然后在命令行上运行 ./mj 程序,也可以启动麻将游戏。哈哈,来句关键的,有没有发现“使用 GNU autotools 改造...
ALI编的麻将连连看,可以作为编写游戏失败的教训参考。
鸡眼麻将(Riichi Mahjong)模拟,分析和玩应用程序。例子有关麻将应用程序和AI的示例,请访问 。用法使用npm update安装依赖项。 使用启动应用程序 node app.js然后访问 。 要分析一只手,请访问 。发展sudo docker...
小时候在游戏厅玩的那种电子麻将,偶然的机会得到一个用c++写的该游戏的源代码,还是跨平台的,在windows和linux下均可编译,执行。其娱乐性就不必说了,而且还是学习跨平台编程的样板。
语言:English,Filipino 麻将是使用一组瓷砖的经典游戏。 此游戏的目标是匹配相同的图块并将其从 麻将是使用一组瓷砖的经典游戏。 该游戏的目标是匹配相同的瓷砖并将其从棋盘上移除。 这将露出下面的瓷砖,并使它们...
麻将Go中的麻将图书馆
Canto Plus麻将网站 专为JA公司Canto +设计的网页,网址为20-21。 这提供了帮助玩家记录他们在麻将中得分的服务。 经过特定的回合数后,网站将为用户提供随机惩罚。 同时,用户也可以输入自己的惩罚。
收藏的unity3d单机4人麻将项目资源,该有的一应俱全。如有需要的自行下载,仅供学习参考,否则后果自负。
用Scala以实用风格编写的麻将API。 受启发包含以下功能: 初始化并打麻将的马来西亚变体游戏。 此变体适用于3个玩家,每个玩家都可以执行,动作,敲击和打Kong动作。 为马来西亚版本使用定制件套,最值得注意的是...
繁体中文棋盘游戏(不是单人模式)。 http://openmahjong.sourceforge.net/的新版本,使用不同的编码模式,包括以下内容:模型-视图-控制器(MVC)。 现在与Chow :-D
Mahjong Solitaire : 300 Puzzle Levels 支持Unity版本5.6.2f1及以上 麻将纸牌:300 个谜题关卡 Unity麻将连连看项目源码C# 麻将纸牌是排名第一的单人纸牌配对游戏,使用一组麻将牌。对于寻求乐趣和广泛重玩的休闲...
python Mahjong
python mahjong
麻将纸牌出于教育目的,用 Java 和 libgdx(有很多 hacky hack)编写。谢谢用于磁贴图标的 KDE Games (libkmahjongg) 背景作者和背景的微妙模式执照除android/assets/data/tiles和android/assets/data/backgrounds...
简单的虚拟麻将-虚拟Riichi麻将- :mahjong_red_dragon: 在HTML5 + Javascript上运行的麻将游戏,其规则不是原始的中国麻将,而是在日本广泛使用的日本麻将。在国际上,日本麻将为Riichi Mahjong。日本麻将。 推荐的...