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.捕第一条鱼的时间是不可避免的,煮每条鱼的时间也是不可避免的,这 ...
随机推荐
- 完全卸载win10上的Ubuntu子系统 - Windows Subsystem for Linux(WSL)
Ctrl + R 键入: lxrun /uninstall /full 具体请看 microsoft的说明:Frequently Asked Questions
- ethtool---查看网卡
ethtool 命令详解 命令描述: ethtool 是用于查询及设置网卡参数的命令. 使用概要:ethtool ethx //查询ethx网口基本设置,其中 x 是对应网卡的编号,如et ...
- ICPC2008哈尔滨-E-Gauss Elimination
题目描述 Li Zhixiang have already been in “Friendship” ocean-going freighter for three months. The excit ...
- Element UI - 打开弹出框(el-dialog)页面会抖动
当 dialog 出现时,页面右边缩小了 5px,模态框看起来会抖动 解决方案 发现 body 多了样式:padding-right: 5px 和 overflow: hidden.紧接着我就在全局设 ...
- Java中的List集合
List集合继承自collection接口,他自己也是个接口,没有具体的结构,与Set集合不同,List集合允许重复的元素. List集合特有方法:(Collection中没有这些) 这些在Arral ...
- leetcode-164周赛-1267-统计参与通信的服务器
题目描述: 自己的提交: class Solution: def countServers(self, grid: List[List[int]]) -> int: from collectio ...
- table响应式设计
table不可用flex布局和td宽度的自适应. table外层加div.mml-table设置overflow-x:auto可以添加横向滚动条.
- 【TCP】SYN攻击
TCP握手协议 在TCP/IP协议中,TCP协议提供可靠的连接服务,采用三次握手建立一个连接.第一次握手:建立连接时,客户端发送syn包(syn=j)到服务器,并进入SYN_SEND状态,等待服务器确 ...
- 【LeetCode 15】三数之和
题目链接 [题解] 先把n个数字升序排个序. 然后枚举三元组最左边的那个数字是第i个数字. 之后用两个指针l,r移动来获取三元组的第2个和第3个数字. (初始值,l=i+1,r = n-1); 如果a ...
- action通信机制
当service通信不能很好的完成任务时候, actionlib则可以比较适合实现长时间的通信过程, actionlib通信过程可以随时被查看过程进度, 也可以终止请求, 这样的一个特性, 使得它在一 ...