首页 > ACM题库 > HDU-杭电 > HDU 3391-Mahjong[解题报告]HOJ
2014
03-23

HDU 3391-Mahjong[解题报告]HOJ

Mahjong

问题描述 :

Mahjong is a wonderful game which origins from China (or maybe Korea because everything is Korean).
Mahjong is also a complex game. But the game we play here is rather easy. It just contains three suits: stones, bamboos and characters.
Stones consist of a number of circles. Each circle is said to represent can (筒, tóng) coins with a square hole in the middle.
Hotel

Bamboos consist of a number of bamboo sticks. Each stick is said to represent a string (索, suǒ) that holds a hundred coins. Note that 1 Bamboo is an exception: it has a bird sitting on a bamboo, to prevent alteration.
Hotel

Each character represents ten thousand (�, wàn) coins.
Hotel

A player wins the round by creating a standard mahjong hand, which consists of a certain number of melds (namely, four for 13-tile variations) and a pair. A meld is three tiles which are adjacent in one suit or all the same. A pair is two same tiles.
Now one player has three tiles in hand. Can you tell what more tile he need to win?
Note that the number of each tile in Mahjong is four. So if the number of one tile the player has is four, he cannot get this tile anymore.

输入:

The first line contains one integer T indicating the number of test cases.
For each case, there are thirteen tiles in one line, separated by one space.
Each tile has two characters. The first character is ‘1’ to ‘9’ and the second is ‘s’ (for stone), ‘b’ (for bamboo), or ‘c’ (for character).

输出:

The first line contains one integer T indicating the number of test cases.
For each case, there are thirteen tiles in one line, separated by one space.
Each tile has two characters. The first character is ‘1’ to ‘9’ and the second is ‘s’ (for stone), ‘b’ (for bamboo), or ‘c’ (for character).

样例输入:

5
1b 1b 2b 2b 3b 3b 5s 6s 7s 1c 1c 2c 2c
3s 4s 4s 5s 5s 5s 6s 6s 7s 9c 9c 4c 5c
1s 1s 1s 2s 3s 4s 5s 6s 7s 8s 9s 9s 9s
4b 5b 6b 7b 8b 8b 8b 2b 3b 4b 5s 6s 7s
4c 5c 6c 9b 9b 9b 9b 1s 2s 3s 2s 3s 4s

样例输出:

Case 1: 1c 2c
Case 2: 3c 6c
Case 3: 1s 2s 3s 4s 5s 6s 7s 8s 9s
Case 4: 1b 3b 4b 6b 7b 9b
Case 5: None

Hint
In case 3, if the player gets 1s, he can combine them into four melds (1s1s1s, 1s2s3s, 4s5s6s, 7s8s9s) and a pair (9s9s). And so it is with 2s to 9s.
2s: 1s1s1s, 3s4s5s, 6s7s8s, 9s9s9s, 2s2s
3s: 1s2s3s, 3s4s5s, 6s7s8s, 9s9s9s, 1s1s
4s: 1s1s1s, 2s3s4s, 4s5s6s, 7s8s9s, 9s9s
5s: 1s1s1s, 2s3s4s, 6s7s8s, 9s9s9s, 5s5s
6s: 1s2s3s, 4s5s6s, 6s7s8s, 9s9s9s, 1s1s
7s: 1s1s1s, 2s3s4s, 5s6s7s, 7s8s9s, 9s9s
8s: 1s1s1s, 2s3s4s, 5s6s7s, 9s9s9s, 8s8s
9s: 1s2s3s, 4s5s6s, 7s8s9s, 9s9s9s, 1s1s

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

int a[10], b[10];

bool check() {
    int cnt = 0;
    for( int i = 1; i <= 9; ++i ) {
	if( b[i] >= 3 ) b[i] -= 3, ++cnt;
	while( i <= 7 && b[i] && b[i+1] && b[i+2] )
	    --b[i], --b[i+1], --b[i+2], ++cnt;
    }
    return cnt == 4;
}

bool ok() {
    for( int i = 1; i <= 9; ++i ) if( a[i] >= 2 ) {
	for( int j = 1; j <= 9; ++j )
	    b[j] = a[j];
	b[i] -= 2;
	if( check() )
	    return true;
    }
    return false;
}

int main()
{
    int x;
    while( cin >> x ) {
	memset(a, 0, sizeof(a)); a[x] = 1;
	for( int i = 1; i <= 12; ++i )
	    cin >> x, ++a[x];
	vector<int> ans;
	for( int i = 1; i <= 9; ++i ) {
	    ++a[i];
	    if( a[i] <= 4 && ok() )
		ans.push_back(i);
	    --a[i];
	}
	for( int i = 0; i < ans.size(); ++i )
	    printf( "%d%c", ans[i], i + 1 == ans.size() ? '\n' : ' ' );
    }
    return 0;
}

  1. 博主您好,这是一个内容十分优秀的博客,而且界面也非常漂亮。但是为什么博客的响应速度这么慢,虽然博客的主机在国外,但是我开启VPN还是经常响应很久,再者打开某些页面经常会出现数据库连接出错的提示

  2. /*
    * =====================================================================================
    *
    * Filename: 1366.cc
    *
    * Description:
    *
    * Version: 1.0
    * Created: 2014年01月06日 14时52分14秒
    * Revision: none
    * Compiler: gcc
    *
    * Author: Wenxian Ni (Hello World~), [email protected]
    * Organization: AMS/ICT
    *
    * =====================================================================================
    */

    #include
    #include

    using namespace std;

    int main()
    {
    stack st;
    int n,i,j;
    int test;
    int a[100001];
    int b[100001];
    while(cin>>n)
    {
    for(i=1;i>a[i];
    for(i=1;i>b[i];
    //st.clear();
    while(!st.empty())
    st.pop();
    i = 1;
    j = 1;

    while(in)
    break;
    }
    while(!st.empty()&&st.top()==b[j])
    {
    st.pop();
    j++;
    }
    }
    if(st.empty())
    cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl;
    }
    return 0;
    }

  3. Hello Web Admin, I noticed that your On-Page SEO is is missing a few factors, for one you do not use all three H tags in your post, also I notice that you are not using bold or italics properly in your SEO optimization. On-Page SEO means more now than ever since the new Google update: Panda. No longer are backlinks and simply pinging or sending out a RSS feed the key to getting Google PageRank or Alexa Rankings, You now NEED On-Page SEO. So what is good On-Page SEO?First your keyword must appear in the title.Then it must appear in the URL.You have to optimize your keyword and make sure that it has a nice keyword density of 3-5% in your article with relevant LSI (Latent Semantic Indexing). Then you should spread all H1,H2,H3 tags in your article.Your Keyword should appear in your first paragraph and in the last sentence of the page. You should have relevant usage of Bold and italics of your keyword.There should be one internal link to a page on your blog and you should have one image with an alt tag that has your keyword….wait there's even more Now what if i told you there was a simple WordPress plugin that does all the On-Page SEO, and automatically for you? That's right AUTOMATICALLY, just watch this 4minute video for more information at.

  4. 因为是要把从字符串s的start位到当前位在hash中重置,修改提交后能accept,但是不修改居然也能accept