题目如下:
A straight is a poker hand containing five cards of sequential rank, not necessarily to be the same suit. For example, a hand containing 7 club, 6 spade, 5 spade, 4 heart and 3 diamond forms a straight. In this problem, we extend the definition of a straight to allow 3 to 5 cards of sequential rank. Hence a hand containing K spade, Q club, and J heart is also a straight.

Mr. Panda is playing a poker game called Straight Master. The game uses a large deck of card that has N ranks from 1 to N. The rule of the game is simple: split the cards in Mr. Panda's hand into several straights of length from 3 to 5.

Now given a hand of cards, can you help Mr. Panda to determine if it is possible to split the cards into straights?

he first line of the input gives the number of test cases, TT test cases follow.

Each test case contains two lines. The first line contains an integer N, indicating the number of ranks in the deck. The next line contains N integers a1, a2, ..., aNindicating the number of cards for each rank in Mr. Panda's hand.

  • 1 ≤ T ≤ 100.
  • 1 ≤ N ≤ 2 × 105.
  • 0 ≤ ai ≤ 109.
  • .

For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y is Yes if Mr. Panda can split all his cards into straights of length from 3 to 5, or No otherwise.

题目大意就是  给好多堆纸牌  我们一次可以在 相邻的三堆各取一张纸牌   或者相邻的四堆中各取一张纸牌  或者五堆中各取一张纸牌  问能不能 全部取完

数据量也比较大  贪心简单做

在做这个题目前  要先搞懂一件事情  就是3 4 5可以拼成任何大于三的数字 比如 7=4+3 9=3+3+3

贪心策略赶紧并不是很好想

可以先举例子

1 2 3 3 5 8 10 5 6 7 4 2

我在这里放了11堆的例子  这11堆安照题目中的规则是可以取完的 
  
为了证明他是可以取完的 我做了下面这串表 在下面中的每一行中 都有数目不少于3个的相同数字
刚才也说过 3 4 5可以组合成任何 不小于3的数字  也就是下面的每一行的个数我都可以用3 4 5获得

1 2 3 3 5 8 10 5 6 7 4 2
1 1 1 1 1 1 1          
  1 1 1 1 1 1          
    1 1 1 1 1          
        2 2 2          
          3 3 3 3 3    
            2 2 2 2 2  
                1 1 1 1
                  1 1 1

我将上面堆 数字做下处理 如下  相邻的相同颜色的几堆代表这 被取走的几堆 数值代表取多少次

1 2 3 3 5 8 10 5 6 7 4 2
1 1 1 1 1 1 1          
  1 1 1 1 1 1          
    1 1 1 1 1          
        2 2 2          
          3 3 3 3 3    
            2 2 2 2 2  
                1 1 1 1
                  1 1 1

通过简单的观察和逻辑推理  就可以注意到  如果我们 第 i 堆 比 第 i-1 堆 要大的话 那么大出来的那部分一定是 某次取牌的最左端的位置
如果 第 i 堆 比 第 i-1 堆小   就不能确定了  但是呢  第 i  堆 要满足一个条件  就是不能断了 前两堆  产生的新最左端位置  意思就是 第i堆的数目一定要 不小于  前三堆正差的和  否则会产生 一个断层就 无解了  在这一堆的结束位置也要满足一个条件  就是 倒数第二堆不能产生新的左端点  如果产生 就要n+1给补上  显然是不可以的  还有就是 倒数第三堆 产生的 左端点 一定要 由末尾补上 否则 也是无解

#include<iostream>
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn = 2e5+;
int a[maxn],b[maxn],flag;
int main()
{
int T,n,cases=;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
n++;
flag=;
for(int i=;i<=n;i++){
scanf("%d",a+i); b[i]=max(a[i]-a[i-],);
}
if(n<=){
printf("Case #%d: No\n",++cases);
continue;
}
for(int i=;i<=n;i++){ if(a[i]<b[i-]+b[i-])
flag=;
}
if(!(b[n]==&&b[n-]==&&a[n]>=b[n-]))
{
flag=;
}
if(!flag)
printf("Case #%d: Yes\n",++cases);
else
printf("Case #%d: No\n",++cases);
}
return ;
}

Straight Master (贪心)的更多相关文章

  1. Gym 101775J Straight Master(差分数组)题解

    题意:给你n个高度,再给你1~n每种高度的数量,已知高度连续的3~5个能消去,问你所给的情况能否全部消去:例:n = 4,给出序列1 2 2 1表示高度1的1个,高度2的2个,高度3的2个,高度4的1 ...

  2. 2017 ECL-FINAL J.Straight Master

    题目链接:http://codeforces.com/gym/101775/problem/J 思路:序列差分一下,然后用得到的查分序列乱搞就可以了 注意差分序列第一项等于a[i],之后n-1项为ch ...

  3. Straight Master Gym-101775J (思维+差分)

    题意:给出N种类的数量,求是否可以把N种牌按3-5张连续的顺子打出,顺子必须连续. 分析:相当于把这个序列分成若干长度为[3,5]的区间,当然其实分成若干段大于3的区间即可.因为大于5的区间又可以分拆 ...

  4. 2017 ACM-ICPC EC-Final ShangHai 东亚洲大陆-上海

    比赛链接:传送门 Gym 101775A Chat Group(签到:待补) Gym 101775B Scapegoat(待补) Gym 101775C Traffic Light(贪心+思维) 思路 ...

  5. 2017-2018 ACM-ICPC Asia East Continent League Final (ECL-Final 2017) Solution

    A:Chat Group 题意:给出一个n, k 计算C(n, k) -> C(n,n) 的和 思路:k只有1e5 反过来想,用总的(2^ n) 减去 C(n, 0) -> C(n, k ...

  6. 2017 ACM-ICPC EC-Final ShangHai(思维乱搞赛)

    感觉全是思维乱搞题. Gym - 101775J Straight Master 给你n种扑克,你每次可以出连续的3 ~ 5 张,问你能否出完. Sample Input 2 13 1 2 2 1 0 ...

  7. 2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛

    传送门 A.^&^ 题意: 找到最小的正数\(C\),满足\((A\ xor\ C)\&(B\ xor \ C)\)最小. 思路: 输出\(A\&B\)即可,特判答案为0的情况 ...

  8. HDU 6709“Fishing Master”(贪心+优先级队列)

    传送门 •参考资料 [1]:2019CCPC网络选拔赛 H.Fishing Master(思维+贪心) •题意 池塘里有 n 条鱼,捕捉一条鱼需要花费固定的 k 时间: 你有一个锅,每次只能煮一条鱼, ...

  9. 【Fishing Master HDU - 6709 】【贪心】

    题意分析 题意:题目给出n条鱼,以及捕一条鱼所用的时间k,并给出煮每一条鱼的时间,问抓完并煮完所有鱼的最短时间. 附题目链接 思路: 1.捕第一条鱼的时间是不可避免的,煮每条鱼的时间也是不可避免的,这 ...

随机推荐

  1. git的使用(本地版本库)

    1. 创建版本库 1.1 创建一个版本库非常简单,首先,选择一个合适的地方,创建一个空目录: 1.2通过git init命令把这个目录变成Git可以管理的仓库(git进入空目录的路径) $ git i ...

  2. java多线程学习笔记(四)

    上一节讲到Synchronized关键字,synchronized上锁的区域:对象锁=方法锁/类锁 本节补充介绍一下synchronized锁重入: 关键字synchronized拥有锁重入的功能,也 ...

  3. centos7 编译打包bcache-tools

    centos7 build bcache-tools 获取源码 centos 本身不提供bcache-tools的rpm,所以需要自己build. 从fedora下载源码,也可以从github社区下载 ...

  4. Django框架(十六)—— cookie和session组件

    目录 cookie和session组件 一.cookie 1.cookie的由来 2.什么是cookie 3.cookie的原理 4.cookie的覆盖 5.在浏览器中查看cookie 6.cooki ...

  5. CSRF如何防御

    总结网上所说,细细的归纳下 CSRF利用的时网站对用户网页浏览器的信任.在受害人不知情的情况下以 受害人的名义伪造请求发送给攻击者的站点. 1.首先XSS漏洞先防护好(一般是通过过滤器更改特殊字符) ...

  6. Python之OS(系统操作)模块常用函数

    mkdir(path[, mode=0777]) makedirs(name,mode=511) rmdir(path) removedirs(path) listdir(path) getcwd() ...

  7. javascript中var同时声明多个变量时的原理是什么?

    <script> function show(){ var a=b=c=d=5; } show(); alert(a);//弹a时报错(not defined),而b.c.d都能弹出5 & ...

  8. OpenGL学习——自定义Shader工具类

    从文件读取Vertex Shader 和 Fragment Shader的工具类. 代码如下: Shader.h #ifndef Shader_h #define Shader_h // GLEW # ...

  9. VMware虚拟机提示找不到vmnetbridge.dl文件的解决办法

    把vmware workstation删了重装,估计是异地安装包在安装时候出现的问题. 先把安装包拷贝到本地,然后控制面板上把已有的vmware workstation删除. 最后重新安装VMware ...

  10. Feign实现服务调用

    上一篇博客我们使用ribbon+restTemplate实现负载均衡调用服务,接下来我们使用feign实现服务的调用,首先feign和ribbon的区别是什么呢? ribbon根据特定算法,从服务列表 ...