HDU 4930 Fighting the Landlords(暴力枚举+模拟)
HDU 4930 Fighting the Landlords
题意:就是题中那几种牌型。假设先手能一步走完。或者一步让后手无法管上,就赢
思路:先枚举出两个人全部可能的牌型的最大值。然后再去推断就可以
代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; struct Player {
int rank[15];
} p1, p2; int t, hash[205], cnt[(1<<20)], vis[20];
char a[25], b[25]; int bitcount(int x) {
int ans = 0;
while (x) {
ans += (x&1);
x >>= 1;
}
return ans;
} void add(int num, Player &p) {
if (num == 2) {
if (vis[14] && vis[15]) {
p.rank[7] = 14;
return;
}
}
if (num == 5) {
int a = 0, b = 0;
for (int i = 15; i >= 1; i--) {
if (vis[i] == 3) a = i;
if (vis[i] == 2) b = i;
}
if (a && b) {
p.rank[5] = max(p.rank[5], a);
}
return;
}
for (int i = 15; i >= 1; i--) {
if (num == 4 && vis[i] == 4) {
p.rank[7] = max(p.rank[7], i);
return;
}
if (num == 4 && vis[i] == 3) {
p.rank[4] = max(p.rank[4], i);
return;
}
if (num == 6 && vis[i] == 4) {
p.rank[6] = max(p.rank[6], i);
return;
}
if (vis[i] == num) {
p.rank[num] = max(p.rank[num], i);
return;
}
}
} void build(char *a, Player &p) {
memset(p.rank, 0, sizeof(p.rank));
int n = strlen(a);
int maxs = (1<<n);
memset(vis, 0, sizeof(vis));
for (int i = 0; i < maxs; i++) {
if (cnt[i] > 6) continue;
memset(vis, 0, sizeof(vis));
for (int j = 0; j < n; j++) {
if (i&(1<<j)) {
vis[hash[a[j]]]++;
}
}
add(cnt[i], p);
}
} bool solve() {
int n = strlen(a);
if (n == 4) {
if (p1.rank[7]) return true;
}
if (n <= 6) {
if (p1.rank[n]) return true;
}
if (p1.rank[7] && p2.rank[7]) return p1.rank[7] > p2.rank[7];
if (p1.rank[7] && !p2.rank[7]) return true;
if (!p1.rank[7] && p2.rank[7]) return false;
for (int i = 1; i < 7; i++) {
if (p1.rank[i] > p2.rank[i]) return true;
}
return false;
} int main() {
for (int i = 0; i < (1<<20); i++)
cnt[i] = bitcount(i);
for (int i = 3; i <= 9; i++)
hash[i + '0'] = i - 2;
hash['T'] = 8; hash['J'] = 9; hash['Q'] = 10; hash['K'] = 11;
hash['A'] = 12; hash['2'] = 13; hash['X'] = 14; hash['Y'] = 15;
scanf("%d", &t);
while (t--) {
scanf("%s%s", a, b);
build(a, p1);
build(b, p2);
if (solve()) printf("Yes\n");
else printf("No\n");
}
return 0;
}
HDU 4930 Fighting the Landlords(暴力枚举+模拟)的更多相关文章
- HDU 4930 Fighting the Landlords(扯淡模拟题)
Fighting the Landlords 大意: 斗地主... . 分别给出两把手牌,肯定都合法.每张牌大小顺序是Y (i.e. colored Joker) > X (i.e. Black ...
- HDU 4930 Fighting the Landlords(模拟)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4930 解题报告:斗地主,加了一个四张可以带两张不一样的牌,也可以带一对,判断打出一手牌之后,如果对手没 ...
- HDU 4930 Fighting the Landlords --多Trick,较复杂模拟
题意:两个人A和B在打牌,只有题目给出的几种牌能出若A第一次出牌B压不住或者A一次就把牌出完了,那么A赢,输出Yes,否则若A牌没出完而且被B压住了,那么A输,输出No. 解法:知道规则,看清题目,搞 ...
- 2014多校第六场 1010 || HDU 4930 Fighting the Landlords (模拟)
题目链接 题意 : 玩斗地主,出一把,只要你这一把对方要不了或者你出这一把之后手里没牌了就算你赢. 思路 : 一开始看了第一段以为要出很多次,实际上只问了第一次你能不能赢或者能不能把牌出尽. #inc ...
- hdu 4930 Fighting the Landlords--2014 Multi-University Training Contest 6
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4930 Fighting the Landlords Time Limit: 2000/1000 MS ...
- hdu 1172 猜数字(暴力枚举)
题目 这是一道可以暴力枚举的水题. //以下两个都可以ac,其实差不多一样,呵呵 //1: //4 wei shu #include<stdio.h> struct tt { ],b[], ...
- hdu 4445 Crazy Tank (暴力枚举)
Crazy Tank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU 4770 Lights Against Dudely 暴力枚举+dfs
又一发吐血ac,,,再次明白了用函数(代码重用)和思路清晰的重要性. 11779687 2014-10-02 20:57:53 Accepted 4770 0MS 496K 2976 B G++ cz ...
- HDU 4431 Mahjong (DFS,暴力枚举,剪枝)
题意:给定 13 张麻将牌,问你是不是“听”牌,如果是输出“听”哪张. 析:这个题,很明显的暴力,就是在原来的基础上再放上一张牌,看看是不是能胡,想法很简单,也比较好实现,结果就是TLE,一直TLE, ...
随机推荐
- 【Codeforces Round #476 (Div. 2) [Thanks, Telegram!] D】Single-use Stones
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 设长度为L的所有区间里面,石头的个数的最小值为k 设取到k的区间为l,r 那么k就为最多能通过的青蛙个数. 假设k再大一点.比如为k ...
- DQL查询语句使用(select)
9)DQL查询语句使用 SELECT语句在PL/SQL中使用,必须 采用下面用法: select id INTO 变量 from t001 where id=5; 将记录字段 ...
- C#-单元测试知识点
指的是软件中对最小单元进行测试的一种测试方法 开发阶段的测试发现问题并解决问题是最节省时间和成本 Ctrl+R Ctrl+A 自动化执行单元测试 查看代码覆盖率,通常要达到80,90%的代码测试覆盖率 ...
- [using_microsoft_infopath_2010]Chapter2 表单需求,使用表决矩阵
本章概要 1.从模板创建表单 2.从创建表单收集需求 3.使用全部表单决策 4.决定需要创建哪种表单
- POJ 1430
上面的估计是题解吧....呃,如果真要用到公式的话,确实没听过.... #include <iostream> #include <cstdio> #include <a ...
- EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP WHEN THEY'RE NOT. RENEWALS ARE LESSER
EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP WHEN THEY'RE NOT. RENEWALS ARE LESSER ...
- How to Hide Zip Files Inside a Picture Without any Extra Software in Windows
http://www.howtogeek.com/119365/how-to-hide-zip-files-inside-a-picture-without-any-extra-software/ c ...
- 88.NODE.JS加密模块CRYPTO常用方法介绍
转自:https://www.jb51.net/article/50668.htm 使用require('crypto')调用加密模块. 加密模块需要底层系统提供OpenSSL的支持.它提供了一种安全 ...
- JS数组去重 包含去除多个 NaN
Array.prototype.uniq = function () { var arr = []; var flag = true; this.forEach(function(item) { ...
- CAS算法
/** * CAS(Compare-And-Swap)算法保证了数据的原子性 * CAS算法是硬件对于并发操作共享数据的支持 * CAS包含了3个操作数: * 内存值 V 看成两步 读取内存值为1步 ...