题目

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2151

题意

麻将,有13张牌,问再加哪一张牌可以凑成一对,若干个三张和若干个三联。

思路

如刘书思路,明显,这是一道模拟题。

感想

1. 三倍ice cream!

代码

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <tuple>
#include <set>
#include <map>
#include <cassert>
#define LOCAL_DEBUG
using namespace std; string cardsName[] = {
"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 cards[14];
bool used[14];
int cardCaches[14];
int cnt[34]; bool read(map<string, int> cardsMap) {
memset(cnt, 0, sizeof cnt);
for (int i = 0; i < 13; i++) {
char tmp[6];
scanf("%s", tmp);
if (tmp[0] == '0')return false;
cards[i] = cardsMap[tmp];
cnt[cards[i]] ++;
}
return true;
} bool subcheck(int sid) {
if (sid > 13)return true;
if (used[sid])return subcheck(sid + 1);
int card = cardCaches[sid];
if (cnt[card] >= 3) {
used[sid] = used[sid + 1] = used[sid + 2] = true;
cnt[card] -= 3;
bool fl = subcheck(sid + 3);
cnt[card] += 3;
used[sid] = used[sid + 1] = used[sid + 2] = false;
if (fl)return true;
}
if (card < 27 && card % 9 < 7 && cnt[card] >0 && cnt[card + 1] > 0 && cnt[card + 2] > 0) {
int tmp[3] = { -1, -1, -1 };
for (int i = sid; i < 14; i++) {
if (used[i])continue;
int ind = cardCaches[i] - cardCaches[sid];
if (tmp[ind] == -1) {
tmp[ind] = i;
}
if (ind == 2)break;
}
for (int ind = 0; ind < 3; ind++) {
cnt[cardCaches[sid] + ind] --;
used[tmp[ind]] = true;
}
bool fl = subcheck(sid + 1);
for (int ind = 0; ind < 3; ind++) {
cnt[cardCaches[sid] + ind] ++;
used[tmp[ind]] = false;
}
if (fl)return true;
}
return false;
} bool check() {
memset(used, 0, sizeof used);
for (int i = 0; i < 14; i++) {
if (i && cardCaches[i] == cardCaches[i - 1])continue;
if (cnt[cardCaches[i]] >= 2) {
used[i] = used[i + 1] = true;
cnt[cardCaches[i]] -= 2;
bool fl = subcheck(0);
used[i] = used[i + 1] = false;
cnt[cardCaches[i]] += 2;
if(fl)return true;
}
}
return false;
} int main() {
#ifdef LOCAL_DEBUG
freopen("input.txt", "r", stdin);
//freopen("output2.txt", "w", stdout);
#endif // LOCAL_DEBUG map<string, int> cardsMap;
for (int i = 0; i < 34; i++) {
cardsMap[cardsName[i]] = i;
}
for (int ti = 1; read(cardsMap); ti++) {
string ans;
for (int i = 0; i < 34; i++) {
if (cnt[i] == 4)continue;
cards[13] = i;
cnt[i]++;
for (int j = 0; j < 14; j++)cardCaches[j] = cards[j];
sort(cardCaches, cardCaches + 14);
if (check()) {
ans += " ";
ans += cardsName[i];
}
cnt[i]--;
} if (ans.length() == 0) {
printf("Case %d: Not ready\n", ti);
}
else {
printf("Case %d:%s\n", ti, ans.c_str());
}
} return 0;
}

  

UVa 11210 - Chinese Mahjong 模拟, 枚举 难度: 0的更多相关文章

  1. uva 11210 Chinese Mahjong(暴力搜索)

    Chinese Mahjong Mahjong () is a game of Chinese origin usually played by four persons with tiles res ...

  2. UVa 11210 Chinese Mahjong (暴力,递归寻找)

    题意:这个题意.有点麻烦,就是说给定13张牌,让你求能“听”的牌.(具体的见原题) 原题链接: https://uva.onlinejudge.org/index.php?option=com_onl ...

  3. UVa 11210 - Chinese Mahjong

    解题报告:麻将的规则这里就不说了,这题我们可以用暴力的方法,所以我们应该这样枚举,即将34张牌的每一张牌都放到原来的十三张牌里面去,所以这时我们只要判断这十四张牌能不能胡,因为若要胡的话一定要有一个对 ...

  4. UVa 10970 - Big Chocolate 水题 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  5. UVa 11389 - The Bus Driver Problem 难度:0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  6. Uva LA 3902 - Network 树形DP 难度: 0

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  7. Uva 11520 - Fill the Square 贪心 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  8. 快速切题 poj 2996 Help Me with the Game 棋盘 模拟 暴力 难度:0

    Help Me with the Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3510   Accepted:  ...

  9. UVA 1508 - Equipment 状态压缩 枚举子集 dfs

    UVA 1508 - Equipment 状态压缩 枚举子集 dfs ACM 题目地址:option=com_onlinejudge&Itemid=8&category=457& ...

随机推荐

  1. 餐E评echarts

    所需要的数据结构 option = { num:1212,//商圈数 numRate:34%,//商圈增长率 activation:1231,//活跃度 activationRate:23%,//活跃 ...

  2. 不光是查找值! "二分搜索"

    2018-11-14 18:14:15 二分搜索法,是通过不断缩小解的可能存在范围,从而求得问题最优解的方法.在程序设计竞赛中,经常会看到二分搜索法和其他算法相结合的题目.接下来,给大家介绍几种经典的 ...

  3. (转)C# Delegate.Invoke、Delegate.BeginInvoke

    Delegate的Invoke.BeginInvoke 1.Delegate.Invoke (委托同步调用) a.委托的Invoke方法,在当前线程中执行委托. b.委托执行时阻塞当前线程,知道委托执 ...

  4. HTML第一章总结

    第一章总结 HTML那些事儿:Web Sever, Web Browser,HTML files 如果你要做网页,那你写了HTML文档就要上传到 Web Server 上 在客户使用 Web Brow ...

  5. delphi 程 序从exe运行改成dll库

    第一种方法: 具体步骤: 1.生成新的或着打开已经存在的工程文件(DPR)(Project1.dpr). 2.选择[View]—>[Project Manager],选中[ProjectGrou ...

  6. English trip V1 - B 17. Giving Information 提供信息 Teacher:Taylor Key: Person Information

    In this lesson you will learn to say your phone number and address.  这节课讲学习说你的手机号码和地址. 课上内容(Lesson) ...

  7. HDOJ-2175 汉诺塔IX

    题目大意:基于汉诺塔原型,第一根柱子上有n个盘子,从上至下编号从1依次递增至n.在最佳移动方案中,第m次所移动的盘子的编号. 解题思路:模拟必然是会超时的.但根据汉诺塔的递归原理,容易发现,对于n阶汉 ...

  8. Confluence 6 修改一个空间从归档到当前

    通过空间目录: 进入头部的 空间(Spaces ) > 空间目录(Space directory). 在左侧 选择 归档的空间(Archived Spaces). 找到你的空间,然后单击右侧的  ...

  9. github第一步之初始化操作

    目录 0.首先注册一个账号 1.创建知识库Repository 2.创建一个分支branch--feature 3.制作并提交commit 4.打开拉取请求pull 5.合并自己的pull请求 git ...

  10. First Bad Version leetcode java

    问题描述: You are a product manager and currently leading a team to develop a new product. Unfortunately ...