题目如下:
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 ;
}

最新文章

  1. js 中 Math对象
  2. GPS部标监控平台的架构设计(十一)-基于Memcached的分布式Gps监控平台
  3. Mysql主从架构的复制原理及配置详解
  4. oc实例变量初始化方法
  5. 微信公众平台开发之微信access_token如何有效长期保存
  6. Angularjs 使用filter格式化输出href
  7. ASP.NET注意事项
  8. VC实现文件拖拽OnDropFiles
  9. Servlet程序开发-- servlet跳转
  10. CSS变量(自定义属性)实践指南
  11. java(一) 基础部分
  12. P2885 [USACO07NOV]电话线Telephone Wire
  13. 如何定位jdk中的native方法源码?
  14. 接口测试-webservice接口---soapui
  15. javascript单线程那些事
  16. Linux - ssh 连接慢解决
  17. 一、java概述
  18. SpringMvc 获取ApplicationContext
  19. TP,TN,FP,FN
  20. 【php】获取ip

热门文章

  1. 【webpack】webpack之postcss-loader的基本使用---【巷子】
  2. 接口自动化测试框架-AIM2.0
  3. Django框架(十六)—— cookie和session组件
  4. ZanUI-WeApp -- 一个颜值高、好用、易扩展的微信小程序 UI 库
  5. oracle中hint 详解
  6. 用dialog包制作窗口
  7. JSP版本的数据库操作
  8. 最全的chrome显示www和https方法(全版本)
  9. SharpZipLib 文件/文件夹 过滤
  10. PHP-两数相除