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, ...
随机推荐
- Mybatis之MySql批量insert后返回主键
需求:使用批量插入后,需要insert之后的每一条记录的ID 注意:Mybatis3.3.1的版本以后支持批量插入后返回主键ID 示例: domin.java: public class User { ...
- Edison Chou
.NET中那些所谓的新语法之中的一个:自己主动属性.隐式类型.命名參数与自己主动初始化器 开篇:在日常的.NET开发学习中,我们往往会接触到一些较新的语法.它们相对曾经的老语法相比.做了非常多的改进, ...
- bzoj-1492 货币兑换Cash (1)——平衡树维护凸包
题意: 有n天和m的初始金钱,用来购买AB两种纪念券: n天里每天都有AB的价格.每天能够进行这种操作. 1.卖出手中x%的纪念券(AB分别都卖出x%). 2.用x的金钱买入纪念券.买入AB券的比例在 ...
- Genymotion出现Installation error: INSTALL_FAILED_CPU_ABI_INCOMPATIBLE错误解决方法
今天在Genymotion上执行曾经的一个项目(libs中有多个SDK和so文件)时,出现下面错误: Console控制台中:Installation error: INSTALL_FAILED_CP ...
- Android recycleView的研究和探讨
RecyclerViewLibrary A RecyclerView libirary ,has some support, like headerAdapter/TreeAdapter,and Pu ...
- MongoDB 数据库下载和安装
MongoDB是一款非常流行的非关系型数据库,将面向对象数据存储做的非常好.这里就不具体介绍它的使用,本文主要解说怎样安装MongoDB数据库.把自己安装过程中碰到的问题和最后解决方法分享给大家,希望 ...
- YII 数据库查询
$userModel = User::Model(); $userModel->count(); $userModel->count($condition); $userModel-> ...
- UVA 11971 - Polygon 数学概率
Polygon John has been given a segment of lenght N, however he n ...
- sts安装出现could not find jar:file解决办法,could not find jar:file,sts安装
标题sts插件下载好但是安装出错 我的eclipse是4.5.2,在官方网站https://spring.io/tools3/sts/legacy下载,压缩包的名字为:spring-tool-suit ...
- Elasticsearch之四种查询类型和搜索原理(博主推荐)
Elasticsearch Client发送搜索请求,某个索引库,一般默认是5个分片(shard). 它返回的时候,由各个分片汇总结果回来. 官网API https://www.elastic.co/ ...