Straight Master (贪心)
题目如下:
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, T. T 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 (贪心)的更多相关文章
- Gym 101775J Straight Master(差分数组)题解
题意:给你n个高度,再给你1~n每种高度的数量,已知高度连续的3~5个能消去,问你所给的情况能否全部消去:例:n = 4,给出序列1 2 2 1表示高度1的1个,高度2的2个,高度3的2个,高度4的1 ...
- 2017 ECL-FINAL J.Straight Master
题目链接:http://codeforces.com/gym/101775/problem/J 思路:序列差分一下,然后用得到的查分序列乱搞就可以了 注意差分序列第一项等于a[i],之后n-1项为ch ...
- Straight Master Gym-101775J (思维+差分)
题意:给出N种类的数量,求是否可以把N种牌按3-5张连续的顺子打出,顺子必须连续. 分析:相当于把这个序列分成若干长度为[3,5]的区间,当然其实分成若干段大于3的区间即可.因为大于5的区间又可以分拆 ...
- 2017 ACM-ICPC EC-Final ShangHai 东亚洲大陆-上海
比赛链接:传送门 Gym 101775A Chat Group(签到:待补) Gym 101775B Scapegoat(待补) Gym 101775C Traffic Light(贪心+思维) 思路 ...
- 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 ...
- 2017 ACM-ICPC EC-Final ShangHai(思维乱搞赛)
感觉全是思维乱搞题. Gym - 101775J Straight Master 给你n种扑克,你每次可以出连续的3 ~ 5 张,问你能否出完. Sample Input 2 13 1 2 2 1 0 ...
- 2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛
传送门 A.^&^ 题意: 找到最小的正数\(C\),满足\((A\ xor\ C)\&(B\ xor \ C)\)最小. 思路: 输出\(A\&B\)即可,特判答案为0的情况 ...
- HDU 6709“Fishing Master”(贪心+优先级队列)
传送门 •参考资料 [1]:2019CCPC网络选拔赛 H.Fishing Master(思维+贪心) •题意 池塘里有 n 条鱼,捕捉一条鱼需要花费固定的 k 时间: 你有一个锅,每次只能煮一条鱼, ...
- 【Fishing Master HDU - 6709 】【贪心】
题意分析 题意:题目给出n条鱼,以及捕一条鱼所用的时间k,并给出煮每一条鱼的时间,问抓完并煮完所有鱼的最短时间. 附题目链接 思路: 1.捕第一条鱼的时间是不可避免的,煮每条鱼的时间也是不可避免的,这 ...
随机推荐
- JS检查断网
window.addEventListener('load', function() { function updateOnlineStatus(event) { var condition = na ...
- Java.io包
Java.io.BufferedInputStream 类添加功能到另一个输入流,缓冲输入以及支持mark和reset methods.Following是关于缓冲输入流的要点: 当创建缓冲输入,创建 ...
- 构建局域网YUM仓库
修改yum源为阿里云源 检验阿里云源是否正常 yum repolist Loaded plugins: fastestmirror Loading mirror speeds from cached ...
- Notepad++中直接运行python
点击进入幕布视图浏览 https://mubu.com/doc/a8VGCUfqqw 一.使用Notepad++编辑python文件,并直接运行 1.用notepad++打开python文件.或者新建 ...
- phpstorm提示phalcon语法
先安装phalcon,将phalcon的扩展php_phalcon.dll添加到PHP的ext目录下,这个不做赘述,网上教程很多 下面直接安装phalcon-devtools, 1,分别下载phalc ...
- 2018-3-5-安装-pip
title author date CreateTime categories 安装 pip lindexi 2018-3-5 19:4:4 +0800 2018-03-05 18:57:15 +08 ...
- grep中正则表达式使用尖括号表示一个单词
比如 grep '\<bin\>' /etc/passwd --color
- HDU-4568 TSP+最短路
题意:给一个n行m列的矩阵,矩阵上的数字代表经过代价(这里要注意每经过一次都要付出代价),矩阵上有几个宝藏,猎人可以从任意边界进去矩阵取完所有宝藏后从任意边界出来. 解法:一看到宝藏数量小于等于13且 ...
- 多线程用this指针来传递参数(整理)
整理自CSDN的论坛中,地址:https://bbs.csdn.net/topics/390703249 1.不同的线程不是两个独立的程序:线程不是进程(process是你说的程序) 2.线程函数必须 ...
- idea创建Maven项目后启动报404
这块的配置是