题目如下:
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. java虚拟机规范(se8)——java虚拟机的编译(一)

    本文翻译自:https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-2.html 第三章 java虚拟机的编译 java虚拟机是设计用来支持ja ...

  2. WPF 动态添加控件以及样式字典的引用(Style introduction)

    原文:WPF 动态添加控件以及样式字典的引用(Style introduction) 我们想要达到的结果是,绑定多个Checkbox然后我们还可以获取它是否被选中,其实很简单,我们只要找到那几个关键的 ...

  3. Codeforces A Mist of Florescence

    A Mist of Florescence 题目大意: 事先告诉你每种颜色分别有几个联通块,构造一个不超过 \(50*50\) 的矩形.用 \(A,B,C,D\) 四种颜色来对矩形进行涂色使它满足要求 ...

  4. 【最新】docker 安装elasticsearch + kibana步骤【第二篇_kibana】

    本文主要讲解Docker 安装 kibana并设置中文语言 [如果有需要安装elasticsearch 的朋友请移步博主第一篇文章] 话不多说! 第一步:docker 下载kibana docker ...

  5. tar - tar 档案文件管理程序的 GNU 版本。

    总览 tar [ - ] A --catenate --concatenate | c --create | d --diff --compare | r --append | t --list | ...

  6. Linux (ifconfig/docker) 移除网桥/虚拟网卡

    今天上大数据实践课时,使用学校提供的云主机平台创建了几台vps,但是安全组配置好之后发现无法用ssh无法登录,ping也不通,提示网络无法到达. 但是拿别人的电脑试了下能顺利使用ssh连接. 有人说是 ...

  7. 【Luogu】【关卡2-10】分治算法(2017年10月)

    任务说明:将大问题拆分为小问题,分而治之,各个击破,然后在合并回来. 取余运算||快速幂 幂次方 逆序对 南蛮图腾

  8. Nodejs进阶:密码加盐

    原理:就是在密码特定位置插入特定字符串后,再对修改后的字符串进行md5运算. demo var crypto=require("crypto"); function cryptPw ...

  9. JS数组 Array

    1.创建数组 var array=new Array(); 2.添加数组 array.push("111"); array.push("111"); array ...

  10. vue 表单校验报错 "Error: please transfer a valid prop path to form item!"

    vue 表单校验报错 "Error: please transfer a valid prop path to form item!" 原因:prop的内容和rules中定义的名称 ...