UVa 11210 - Chinese Mahjong 模拟, 枚举 难度: 0
题目
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的更多相关文章
- uva 11210 Chinese Mahjong(暴力搜索)
Chinese Mahjong Mahjong () is a game of Chinese origin usually played by four persons with tiles res ...
- UVa 11210 Chinese Mahjong (暴力,递归寻找)
题意:这个题意.有点麻烦,就是说给定13张牌,让你求能“听”的牌.(具体的见原题) 原题链接: https://uva.onlinejudge.org/index.php?option=com_onl ...
- UVa 11210 - Chinese Mahjong
解题报告:麻将的规则这里就不说了,这题我们可以用暴力的方法,所以我们应该这样枚举,即将34张牌的每一张牌都放到原来的十三张牌里面去,所以这时我们只要判断这十四张牌能不能胡,因为若要胡的话一定要有一个对 ...
- UVa 10970 - Big Chocolate 水题 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVa 11389 - The Bus Driver Problem 难度:0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- Uva LA 3902 - Network 树形DP 难度: 0
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- Uva 11520 - Fill the Square 贪心 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- 快速切题 poj 2996 Help Me with the Game 棋盘 模拟 暴力 难度:0
Help Me with the Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3510 Accepted: ...
- UVA 1508 - Equipment 状态压缩 枚举子集 dfs
UVA 1508 - Equipment 状态压缩 枚举子集 dfs ACM 题目地址:option=com_onlinejudge&Itemid=8&category=457& ...
随机推荐
- eclipse创建web项目web.xml配置文件笔记
1.使用eclipse创建web项目时,如果直接finish的话就没有默认生成web.xml配置文件,此时在你的项目下是看不到web.xml配置文件的,如果要查看的话可以如下操作: 右键你的项目,然后 ...
- 《剑指offer》第四十一题(数据流中的中位数)
// 面试题41:数据流中的中位数 // 题目:如何得到一个数据流中的中位数?如果从数据流中读出奇数个数值,那么 // 中位数就是所有数值排序之后位于中间的数值.如果从数据流中读出偶数个数值, // ...
- LRN(local response normalization--局部响应标准化)
LRN全称为Local Response Normalization,即局部响应归一化层,LRN函数类似DROPOUT和数据增强作为relu激励之后防止数据过拟合而提出的一种处理方法.这个函数很少使用 ...
- nRF52832-GPIOTE部分
GPIOTE部分学习思维导图 GPIOTE原理 1.1nRF52832寄存器类型 Task:任务寄存器,可以由程序或事件触发 Event:事件寄存器,事件可以产生中断和触发任务 Register:普通 ...
- lumerical中DEVICE和MODE模块的交互使用(真的很干货!!可以自信的说网上绝对找不到比我更详细的步骤了)
几个脚本文件很重要! Lumerical仿真流程: 一.DEVICE: (1).建模并且运行完之后,在脚本提示符下键入以下脚本行以运行plotDopingProfile.lsf如图1(文件名如果索引不 ...
- Navicat Premium 12如何激活
Navicat Premium 12如何激活 一.总结 一句话总结:激活过程中一定要断开网络连接,点电脑的飞行模式没有用,断开网络连接之后才有手动激活的选项 需要断网 点电脑的飞行模式无用 二.Nav ...
- 宿主iis部署wcf
WCF学习笔记(4)——宿主iis部署wcf 本文将部署一个wcf+silverlight简单实例,以下是详细步骤: (环境:服务端win2003,iis6.0,asp.net4.0:客户端winXP ...
- confirm提示弹出确定和取消按钮
js----> var con = confirm('这是一个确定加取消的提示窗口') if(con==true){ document.write("点击了确定按钮") }e ...
- CF1114E Arithmetic Progression
给定一个打乱的等差数列,每次两种操作. 1.查询一个位置. 2.查询是否有比x大的数字. 一共60次操作. sol: 30次操作即可二分出首项. 剩下30次操作查询出30个位置然后两两做差取gcd即可 ...
- python记录_day15 面向对象初识
一.面向过程和面向对象 1.面向过程 以我为中心,做一件事先干什么,在干什么,后干什么,有一套清楚完整的流程.核心是“过程”. 优点:将要解决的问题流程化, 编写相对简单 缺点:可扩展性差 2.面向对 ...