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 235B】Let's Play Osu!
[题目链接]:http://codeforces.com/problemset/problem/235/B [题意] 让你玩一个游戏,游戏结果由一个长度为n的01字符组成; 这个结果的分数与连续的1的 ...
- 【codeforces 508D】The Maths lecture
[题目链接]:http://codeforces.com/problemset/problem/507/D [题意] 让你找符合这样数字的数的个数: 1.有n个数码 2.某个后缀%k的值为0 3.大于 ...
- open函数详解
转载:https://www.cnblogs.com/frank-yxs/p/5925574.html open函数用来在进程中打开文件,如果成功则返回一个文件描述符fd. ============= ...
- Nutch2 WebPage写入数据库的过程分析
版本: Nutch 2.2.1 本文通过InjectJob来追踪webpage的定义.创建.传递.序列化.写入数据库的整个过程.从源码中摘录了重要的代码行,并标明其所在文件名.行号. 1. 定义 sc ...
- Java程序命令行打包Jar
最近要跑爬虫程序,需要打包成jar发在linux服务器中运行.主要是第三方的lib包与配置文件,不进行打包,方便修改. 1.eclipse中src中源码编译后生成的源码在bin文件中,把里面源码单独拿 ...
- [CSS3] All abourt responsive image
Take few examples: Full size image: The problem for that is it overflow when the screen size is smal ...
- hunnu11544:小明的烦恼——找字符串
Problem description 小明是个非常优秀的同学.他除了特别公正外,他也非常细心,当然老师肯定也知道,这不,老师又有事情找他帮忙了.老师每周都会给他一个字符串A.然后问小明" ...
- 弹性ScrollView,和下啦刷新的效果相似 实现下拉弹回和上拉弹回
今天做了一个弹性ScrollView,和下啦刷新的效果类似,我想这个非常多需求都用的这样的效果 事实上这是一个自己定义的scrollView,上代码.这是我写在一个公共的组件包里的 package c ...
- linux数据库升级
转自:老左博客:http://www.laozuo.org/6145.html 老左今天有在帮朋友的博客搬迁到另外一台VPS主机环境,其环境采用的是LLSMP架构的,原先的服务器采用的是LNMP网站环 ...
- javascript系列-Class1.JavaScript基础
欢迎加入前端交流群来py:749539640 转载请标明出处! JavaScript概述 一个页面分成三个部分,结构,样式,行为. HTML代表了页面的结 ...