标签:contain img init 数值 简单 合成 不可 n+1 while
题目如下:
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.
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 |
#include<iostream> #include<stdio.h> #include<cstring> #include<algorithm> #include<queue> using namespace std; const int maxn = 2e5+7; int a[maxn],b[maxn],flag; int main() { int T,n,cases=0; scanf("%d",&T); while(T--){ scanf("%d",&n); n++; flag=0; for(int i=2;i<=n;i++){ scanf("%d",a+i); b[i]=max(a[i]-a[i-1],0); } if(n<=3){ printf("Case #%d: No\n",++cases); continue; } for(int i=2;i<=n;i++){ if(a[i]<b[i-1]+b[i-2]) flag=1; } if(!(b[n]==0&&b[n-1]==0&&a[n]>=b[n-2])) { flag=1; } if(!flag) printf("Case #%d: Yes\n",++cases); else printf("Case #%d: No\n",++cases); } return 0; }
标签:contain img init 数值 简单 合成 不可 n+1 while
原文地址:https://www.cnblogs.com/DWVictor/p/10283206.html