HDU 4930 Fighting the Landlords --多Trick,较复杂模拟
题意:两个人A和B在打牌,只有题目给出的几种牌能出若A第一次出牌B压不住或者A一次就把牌出完了,那么A赢,输出Yes,否则若A牌没出完而且被B压住了,那么A输,输出No。
解法:知道规则,看清题目,搞清有哪些Trick,就可以直接模拟搞了。详见代码:
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <cstdlib>
- #include <cmath>
- #include <algorithm>
- #include <vector>
- #include <queue>
- using namespace std;
- #define N 100102
- #define M 22
- char s1[],s2[];
- int A[],B[];
- int cnt1[],cnt2[];
- int main()
- {
- int n,i,j;
- int n1,n2;
- scanf("%d",&n);
- while(n--)
- {
- priority_queue<int> Single,Pair,Tri,Four,Nuke;
- priority_queue<int> Single2,Pair2,Tri2,Four2,Nuke2;
- scanf("%s",s1);
- scanf("%s",s2);
- n1 = strlen(s1);
- n2 = strlen(s2);
- for(i=;i<n1;i++)
- {
- if(s1[i] >= '' && s1[i] <= '')
- A[i] = s1[i]-'';
- else if(s1[i] == 'T')
- A[i] = ;
- else if(s1[i] == 'J')
- A[i] = ;
- else if(s1[i] == 'Q')
- A[i] = ;
- else if(s1[i] == 'K')
- A[i] = ;
- else if(s1[i] == 'A')
- A[i] = ;
- else if(s1[i] == '')
- A[i] = ;
- else if(s1[i] == 'X')
- A[i] = ;
- else if(s1[i] == 'Y')
- A[i] = ;
- }
- for(i=;i<n2;i++)
- {
- if(s2[i] >= '' && s2[i] <= '')
- B[i] = s2[i]-'';
- else if(s2[i] == 'T')
- B[i] = ;
- else if(s2[i] == 'J')
- B[i] = ;
- else if(s2[i] == 'Q')
- B[i] = ;
- else if(s2[i] == 'K')
- B[i] = ;
- else if(s2[i] == 'A')
- B[i] = ;
- else if(s2[i] == '')
- B[i] = ;
- else if(s2[i] == 'X')
- B[i] = ;
- else if(s2[i] == 'Y')
- B[i] = ;
- }
- sort(A,A+n1);
- sort(B,B+n2);
- memset(cnt1,,sizeof(cnt1));
- memset(cnt2,,sizeof(cnt2));
- for(i=;i<n1;i++) //计算A各种牌的个数
- cnt1[A[i]]++;
- for(i=;i<n2;i++) //计算B各种牌的个数
- cnt2[B[i]]++;
- for(i=;i<=;i++)
- {
- if(cnt1[i] == ) //出现四个,可以做四个出,可以做三个出,也可以做两个或一个出
- Four.push(i),Tri.push(i),Pair.push(i),Single.push(i);
- else if(cnt1[i] == )
- Tri.push(i),Pair.push(i),Single.push(i);
- else if(cnt1[i] == )
- Pair.push(i),Single.push(i);
- else if(cnt1[i] == )
- Single.push(i);
- }
- for(i=;i<=;i++)
- {
- if(cnt2[i] == )
- Four2.push(i),Tri2.push(i),Pair2.push(i),Single2.push(i);
- else if(cnt2[i] == )
- Tri2.push(i),Pair2.push(i),Single2.push(i);
- else if(cnt2[i] == )
- Pair2.push(i),Single2.push(i);
- else if(cnt2[i] == )
- Single2.push(i);
- }
- if(cnt1[]) //有王,可以做单个出
- Nuke.push(),Single.push();
- if(cnt1[])
- Nuke.push(),Single.push();
- if(cnt2[])
- Nuke2.push(),Single2.push();
- if(cnt2[])
- Nuke2.push(),Single2.push();
- if(Nuke.size() >= ) //双王,直接赢
- {
- puts("Yes");
- continue;
- }
- //-------------------------------下面判断能否一次出完
- if(n1 == )
- {
- puts("Yes");
- continue;
- }
- if(n1 == )
- {
- if(A[] == A[])
- {
- puts("Yes");
- continue;
- }
- }
- if(n1 == )
- {
- if(A[] == A[] && A[] == A[])
- {
- puts("Yes");
- continue;
- }
- }
- if(n1 == )
- {
- if(A[] == A[] && A[] == A[] && A[] == A[])
- {
- puts("Yes");
- continue;
- }
- if(A[] != A[] && A[] == A[] && A[] == A[])
- {
- puts("Yes");
- continue;
- }
- if(A[] != A[] && A[] == A[] && A[] == A[])
- {
- puts("Yes");
- continue;
- }
- }
- if(n1 == )
- {
- if(A[] == A[] && A[] != A[] && A[] == A[] && A[] == A[])
- {
- puts("Yes");
- continue;
- }
- if(A[] == A[] && A[] != A[] && A[] == A[] && A[] == A[])
- {
- puts("Yes");
- continue;
- }
- }
- if(n1 == )
- {
- int tag = ;
- for(i=;i<=;i++)
- {
- if(A[i] == A[i+] && A[i+] == A[i+] && A[i+] == A[i+])
- {
- tag = ;
- break;
- }
- }
- if(tag)
- {
- puts("Yes");
- continue;
- }
- }
- //-----------------------------如果不能一次出完
- if(Nuke2.size() >= ) //对方有双王,必输
- {
- puts("No");
- continue;
- }
- if(!Nuke.empty() && Nuke2.empty()) //A有王,B没王
- {
- puts("Yes");
- continue;
- }
- if(!Nuke.empty() && !Nuke2.empty()) //都有王,看谁的大,如果A小,则不选择出王,继续
- {
- if(Nuke.top() > Nuke2.top())
- {
- puts("Yes");
- continue;
- }
- }
- if(Four.empty() && !Four2.empty()) //炸弹,如果不能一次出完又没炸弹,那么必会被炸,输
- {
- puts("No");
- continue;
- }
- if(!Four.empty() && Four2.empty()) //有炸弹出炸弹
- {
- puts("Yes");
- continue;
- }
- if(!Four.empty() && !Four2.empty()) //都有炸弹,A的如果小,因为不能一次出完,必输
- {
- if(Four.top() >= Four2.top())
- {
- puts("Yes");
- continue;
- }
- else
- {
- puts("No");
- continue;
- }
- }
- if(!Tri.empty() && Tri2.empty()) //三个的情况
- {
- puts("Yes");
- continue;
- }
- if(!Tri.empty() && !Tri2.empty())
- {
- if(Tri.top() >= Tri2.top())
- {
- puts("Yes");
- continue;
- }
- else if(n1 >= && n2 <= ) //A有的带,B没得带
- {
- puts("Yes");
- continue;
- }
- }
- if(!Pair.empty() && Pair2.empty()) //对子
- {
- puts("Yes");
- continue;
- }
- if(!Pair.empty() && !Pair2.empty())
- {
- if(Pair.top() >= Pair2.top())
- {
- puts("Yes");
- continue;
- }
- }
- if(Single.empty() && !Single2.empty()) //单个牌
- {
- puts("No");
- continue;
- }
- if(!Single.empty() && Single2.empty())
- {
- puts("Yes");
- continue;
- }
- if(!Single.empty() && !Single2.empty())
- {
- if(Single.top() >= Single2.top())
- {
- puts("Yes");
- continue;
- }
- }
- puts("No"); //如果以上都不满足,那么A输了,gg。
- }
- return ;
- }
HDU 4930 Fighting the Landlords --多Trick,较复杂模拟的更多相关文章
- HDU 4930 Fighting the Landlords(暴力枚举+模拟)
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 解题报告:斗地主,加了一个四张可以带两张不一样的牌,也可以带一对,判断打出一手牌之后,如果对手没 ...
- 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 ...
- hdu4930 Fighting the Landlords(模拟 多校6)
题目链接:pid=4930">http://acm.hdu.edu.cn/showproblem.php? pid=4930 Fighting the Landlords Time L ...
- HDU4930 Fighting the Landlords 模拟
Fighting the Landlords Fighting the Landlords Time Limit: 2000/1000 MS (Java/Others) Memory Limit ...
- hdu 4930 斗地主恶心模拟
http://acm.hdu.edu.cn/showproblem.php?pid=4930 就是两个人玩斗地主,有8种牌型,单张,一对,三张,三带一,三带对,四带二,四炸,王炸.问先手能否一次出完牌 ...
- HDOJ(HDU) 2109 Fighting for HDU(简单排序比较)
Problem Description 在上一回,我们让你猜测海东集团用地的形状,你猜对了吗?不管结果如何,都没关系,下面我继续向大家讲解海东集团的发展情况: 在最初的两年里,HDU发展非常迅速,综合 ...
随机推荐
- C语言范例学习03-上
第三章 数据结构 章首:不好意思,这两天要帮家里做一些活儿.而且内容量与操作量也确实大幅提升了.所以写得很慢. 不过,从今天开始.我写的东西,许多都是之前没怎么学的了.所以速度会慢下来,同时写得也会详 ...
- 关于setInterval和setTImeout中的this指向问题
前些天在练习写一个小例子的时候用到了定时器,发现在setInterval和setTimeout中传入函数时,函数中的this会指向window对象,如下例: var num = 0; function ...
- JS创建对象、继承原型、ES6中class继承
面向对象编程:java中对象的两个基本概念:1.类:类是对象的模板,比如说Leader 这个是泛称领导,并不特指谁.2:实例:实例是根据类创建的对象,根据类Leader可以创建出很多实例:liyi,y ...
- 移动端H5---页面适配问题详谈(一)
一.前言 昨天唠叨了哈没用的,今天说点有用的把.先说一下响应式布局吧,我一直认为响应式布局的分项目,一下布局简单得项目做响应式还是可以可以得.例如博客.后台管理系统等.但是有些会认为响应式很牛逼,尤其 ...
- git学习笔记2
工作区和暂存区 Git和其他版本控制系统如SVN的一个不同之处就是有暂存区的概念. 先来看名词解释. 工作区(Working Directory) 就是你在电脑里能看到的目录,比如我的github文件 ...
- 基础学习day12--多线程一线程之间的通信和常用方法
一.线程之间的通信 1.1.线程之间的通信方法 多个线程在处理统一资源,但是任务却不同,这时候就需要线程间通信. 等待/唤醒机制涉及的方法: 1. wait():让线程处于冻结状态,被wa ...
- 菜鸟教程 Python100例 之实例29
学习编程的路,走得好艰辛... 为了巩固基础知识,把菜鸟教程网上的实例拿来练习.. 在做到实例29时,看了网站给出的代码,觉得可以加强一下功能,不由得动了一下脑筋,如下: 原文题目: 题目:给一个不多 ...
- bsearch
在java中为了避免 low+high溢出,可以用无符号右移:正数高位补0,负数高位补1 int mid = (low + high) >>> 1; 如果是在c++中,那么需要先转换 ...
- Windows Server 2008 下ASP程序连接ORACLE数据库驱动错误
今天开发那边升级.改造系统过程中,在测试服务器碰到关于ASP程序连接ORACLE数据库的小问题,虽然是小问题,但是整起来真要命啊,花了不少时间,主要是ASP程序啊,这种上古神器,哥还是当年毕业的时候弄 ...
- sql server 导出的datetime结果 CAST(0x00009E0E0095524F AS DateTime) 如何向mysql,oracle等数据库进行转换
1. 处理 sql server 导出的 datetime 类型的字段 在进行sql server向mysql等其他数据进行迁移数据时,会发现使用sql server导出的datetime类型的结果是 ...