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, ...
随机推荐
- NYIST 973 天下第一
天下第一时间限制:1000 ms | 内存限制:65535 KB难度:3 描述AC_Grazy一直对江湖羡慕不已,向往着大碗吃肉大碗喝酒的豪情,但是“人在江湖漂,怎能 不挨刀",”人在江湖身 ...
- POJ 2480
可以容易得知,F=sum(p*phi(n/p)).思路就断在这里了... 看过别人的,才知道如下: 由于gcd(i,n*m)=gcd(i,m)*gcd(i,n),所以gcd为积性函数.而积性函数之和为 ...
- 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 ...
- HTML5图片上传预览
HTML5实现图片的上传预览,需要使用FileReader对象. FileReader: The FileReader object lets web applications asynchronou ...
- Testbench代码设计技巧
Testbench代码设计技巧 " There are many ways " to code a test case, it all depens on the creativi ...
- JAVA设计模式之【模板方法模式】
模板方法模式 提高代码的复用性 把常用的基本方法放入父类中 强调一种流程步骤 角色 抽象类 抽象方法 具体方法 钩子方法 空方法 通过bool控制 具体类 看例子 1.银行模板类 package Te ...
- 18.boost 图的拓扑排序
运行结果: 代码示例: #include <iostream> #include <vector> #include <deque> #include <bo ...
- BZOJ 4260 trie树
思路: 搞一个前缀异或和 一次从左往右 另一次从右往左 异或最大值 用字典树搞一搞 //By SiriusRen #include <cstdio> #include <cstrin ...
- C# 导出excel的压缩包到浏览器页面
需求背景:TCX_1710项目产品质量导出功能,客户希望每个总成导出到一个Excel表中 实现分析:客户选择时间段,点击导出按钮,默认导出开始时间当天的数据,每个总成一个Excel,将各个Excel打 ...
- C#小代码
1.创建随机ID: Id = Guid.NewGuid().ToString("N"); 2.创建随机时间: CreationTime = DateTime.Now: int st ...