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, ...
随机推荐
- Docker可视化管理工具对比(DockerUI、Shipyard、Rancher、Portainer)
1.前言 谈及docker,避免不了需要熟练的记住好多命令及其用法,对于熟悉shell.技术开发人员而言,还是可以接受的,熟练之后,命令行毕竟是很方便的,便于操作及脚本化.但对于命令行过敏.非技术人员 ...
- ASP.NET-未解决的问题
001.((FormsIdentity)User.Identity).Ticket.UserData 用ASP.NET后台格式化成json数据后传回去的数据有"这样的符号 002.HT ...
- 洛谷 P1278 单词游戏
P1278 单词游戏 题目描述 Io和Ao在玩一个单词游戏. 他们轮流说出一个仅包含元音字母的单词,并且后一个单词的第一个字母必须与前一个单词的最后一个字母一致. 游戏可以从任何一个单词开始. 任何单 ...
- HDU 5410(2015多校10)-CRB and His Birthday(全然背包)
题目地址:HDU 5410 题意:有M元钱,N种礼物,若第i种礼物买x件的话.会有Ai*x+Bi颗糖果,现给出每种礼物的单位价格.Ai值与Bi值.问最多能拿到多少颗糖果. 思路:全然背包问题. dp[ ...
- OpenCV基础篇之读取显示图片
程序及分析 /* * FileName : read.cpp * Author : xiahouzuoxin @163.com * Version : v1.0 * Date : Tue 13 May ...
- MVC 从View像Controller中传值
在上一篇博客中总结了一下从Controller像View中传值的几种方法.事实上看那些方法和在我们最初学习VB的时候一样,将数据库中的数据显示到前台的页面.数据库还是那个数据库,仅仅是如今前台变成了浏 ...
- 百度地图----->地图类型、定位模式、实时交通、我的位置、加入覆盖物、覆盖物详情及提示
在百度地图开发平台 http://developer.baidu.com/map/index.php? title=androidsdk 进行创建应用,获取应用的AK,在进行下载BaiduLBS_An ...
- 杭电3501Calculation 2 欧拉函数
Calculation 2 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- 从零开始编写一个vue插件
title: 从零开始编写一个vue插件 toc: true date: 2018-12-17 10:54:29 categories: Web tags: vue mathjax 写毕设的时候需要一 ...
- BZOJ 2045 容斥原理
思路: 同BZOJ 2005 http://blog.csdn.net/qq_31785871/article/details/54314774 //By SiriusRen #include < ...