Mahjong is a game of skill, strategy and calculation and involves a certain degree of chance. In this problem, we concentrate on Japanese Mahjong, a variation of mahjong. For brief, all of the word mahjong mentioned following refer to Japanese Mahjong.
Japanese mahjong is usually played with 136 tiles, which can be Z喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcmdhbml6ZWQgaW50byBzZXZlcmFsIGNhdGVnb3JpZXM6PC9wPgo8dWw+CjxlbT5TdWl0ZWQgdGlsZXM8L2VtPi4gQWxsIHN1aXRlZCB0aWxlcyBhcmUgb2YgYSByYW5rIGFuZCBhIHN1aXQuVGhlcmUgYXJlIHRocmVlIHN1aXRzIG9mIHRpbGVzLCB3aXRoIHJhbmtzIHJhbmdpbmcgZnJvbSBvbmUgdG8gbmluZS4gVGhlcmUgYXJlIGZvdXIgdGlsZXMgb2YgZWFjaCByYW5rIGFuZCBzdWl0IGNvbWJpbmF0aW9uLCB0aHVzIHRoZXJlIGFyZSAzNiB0aWxlcyBpbiBhIHN1aXQsIGFuZCAxMDggc3VpdGVkIHRpbGVzIGluIHRvdGFsLgoKVGhlIDxlbT5jaXJjbGU8L2VtPiBzdWl0PGJyPgo8aW1nIHNyYz0="http://www.2cto.com/uploadfile/Collfiles/20140513/20140513090818326.jpg" alt="\">The bamboo suit
The character suit
Honor tiles. Honor Tiles are tiles that do not have a rank or suit. They are divided into two categories. There are four types of Wind tiles and three types of Dragon tiles, with four of each type of honor tile. Thus, there are 16 wind tiles and
12 Dragon tiles for 28 honor tiles.
Wind tiles. The Wind tiles consist of four kinds of tile: East, South, West, and North.
Dragon tiles. The Dragon titles consist of three types of tile: Red, Green, White.
A winning hand consists of fourteen tiles, which is made of four melds (a specific pattern of three pieces) and the eyes (a pair of two identical pieces). The definition of melds and eyes is given as followed:
When a hand is one tile short of winning, 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. Now, given thirteen tiles, can you answer how many types of tiles you are waiting for a winning hand? If the given hand were not a ready hand, output an integer zero instead.
There are multiple cases. Each case consists of 26 characters in one line, describing thirteen tiles. The manner for describing each type of tile is:
For each case, first output the number of types of tiles you are waiting for in one line. Then output each type of tile you are waiting for in the manner described above. output them in this fixed order: 'm', 'p', 's', 'z', and for each suit, smaller rank first (Honor tiles is similar to suited tiles, only using the integer standing for in above manner instead of suited rank).
1s1s1s2p3p4p6m7m8m1z1z1z2z 1s1s1s2p3p4p6m7m8m1z1z1z9m 1s1s1s2p3p4p6m7m8m1z1z1z1z 1s2s3s1s2s3s2s3s7s8s9s6z6z
1 2z 2 6m9m 0 3 1s4s6z
題意
按一題目的要求輸出摸到那些牌能胡牌
#include#include #include using namespace std; struct node { int num; char kind; } s[100000]; char str[100]; int a[4][15]; int ta[4][15]; int len,cnt; int find(int num)//找出4個三個一組的 { int i,j; if(num == 0) return 1; for(i = 0; i<4; i++)//找出三個一樣的 { for(j = 1; j<=9; j++) { if(a[i][j]<3) continue; a[i][j]-=3; if(find(num-1)) return 1; a[i][j]+=3; } } for(i = 0; i<3; i++)//找出一句話 { for(j = 1; j<=7; j++) { if(a[i][j] && a[i][j+1] && a[i][j+2]) { a[i][j]--,a[i][j+1]--,a[i][j+2]--; if(find(num-1)) return 1; a[i][j]++,a[i][j+1]++,a[i][j+2]++; } } } return 0; } int solve() { int i,j; for(i = 0; i<4; i++) { for(j = 1; j<=9; j++) { if(a[i][j]<2) continue; if(i==3 && j<=7) { a[i][j]-=2; if(find(4)) return 1; a[i][j]+=2; } else { a[i][j]-=2; if(find(4)) return 1; a[i][j]+=2; } } } return 0; } int main() { int i,j,k; while(~scanf("%s",str)) { cnt = 0; memset(a,0,sizeof(a)); for(i = 0; i<26; i+=2) { if(str[i+1] == 'm') a[0][str[i]-'0']++; else if(str[i+1] == 'p') a[1][str[i]-'0']++; else if(str[i+1] == 's') a[2][str[i]-'0']++; else if(str[i+1] == 'z') a[3][str[i]-'0']++; } char kind[5]="mpsz"; for(i = 1; i<=27+7; i++)//枚舉所有摸到的牌 { int id = (i-1)/9; int no = i%9; if(no == 0) no = 9; memcpy(ta,a,sizeof(a)); if(id<4 && a[id][no]<4)//只有小於四張才能摸到 a[id][no]++; else continue; if(solve()) { s[cnt].num = no; s[cnt].kind = kind[id]; cnt++; } memcpy(a,ta,sizeof(ta)); } if(cnt == 0) { printf("0\n"); continue; } printf("%d ",cnt); for(i = 0; i