HDU 4272 LianLianKan
来源:互联网 发布:软件研发部门规划 编辑:程序博客网 时间:2024/05/19 14:36
LianLianKan
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4093 Accepted Submission(s): 1231
Problem Description
I like playing game with my friend, although sometimes looks pretty naive. Today I invent a new game called LianLianKan. The game is about playing on a number stack.
Now we have a number stack, and we should link and pop the same element pairs from top to bottom. Each time, you can just link the top element with one same-value element. After pop them from stack, all left elements will fall down. Although the game seems to be interesting, it's really naive indeed.
To prove I am a wisdom among my friend, I add an additional rule to the game: for each top element, it can just link with the same-value element whose distance is less than 6 with it.
Before the game, I want to check whether I have a solution to pop all elements in the stack.
Now we have a number stack, and we should link and pop the same element pairs from top to bottom. Each time, you can just link the top element with one same-value element. After pop them from stack, all left elements will fall down. Although the game seems to be interesting, it's really naive indeed.
To prove I am a wisdom among my friend, I add an additional rule to the game: for each top element, it can just link with the same-value element whose distance is less than 6 with it.
Before the game, I want to check whether I have a solution to pop all elements in the stack.
Input
There are multiple test cases.
The first line is an integer N indicating the number of elements in the stack initially. (1 <= N <= 1000)
The next line contains N integer ai indicating the elements from bottom to top. (0 <= ai <= 2,000,000,000)
The first line is an integer N indicating the number of elements in the stack initially. (1 <= N <= 1000)
The next line contains N integer ai indicating the elements from bottom to top. (0 <= ai <= 2,000,000,000)
Output
For each test case, output “1” if I can pop all elements; otherwise output “0”.
Sample Input
21 131 1 121000000 1
Sample Output
100
题目大意:连连看,不超过5的距离的两个相同的元素可以消除
模拟一下
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int num[1010];int book[1010];int main(){//freopen("in.txt","r",stdin);int n;while(cin>>n){memset(book,0,sizeof(book));for(int i=1;i<=n;i++) scanf("%d",&num[i]);int cnt=0;while(cnt<n){int i;for(i=1;i<=n;i++){if(book[i]) continue;int step=0;for(int j=i+1;j<=n&&step<=5;j++){if(book[j]) continue;else{if(num[j]==num[i]){book[j]=book[i]=1;break;}}step++;}}//第一次消除时可能会因为两个元素间有很多可以消除但是//并未消除的元素,消除中间元素以后就可以消除了,但是因为每次//循环都是往后边的元素找,所以我们要多次重新开始循环//确保可以消除的都消除//比如3 5 5 6 6 7 7 8 8 3 cnt++;}int i;for(i=1;i<=n;i++){if(!book[i]){cout<<0<<endl;break;}}if(i>n) cout<<1<<endl;}}
阅读全文
0 0
- HDU 4272 LianLianKan(贪心!!!!!)
- hdu 4272 LianLianKan
- hdu 4272 LianLianKan
- HDU 4272 lianliankan
- HDU 4272 LianLianKan
- 【HDU】4272 LianLianKan(DFS)
- Hdu 4272 LianLianKan(贪心+链表)
- HDU 4272 LianLianKan(模拟)
- HDU 4272 LianLianKan 状态压缩DP
- HDU 4272 LianLianKan 记忆化搜索
- HDU 4272 LianLianKan DFS+map优化
- hdu 4272 LianLianKan(模拟dfs+map)
- LianLianKan
- LianLianKan
- lianliankan
- LianLianKan
- hdoj 4272 LianLianKan 【树状数组】
- HDOJ 4272 LianLianKan(简单模拟)
- dp动态规划分类详解
- gdb调试多线程
- SPOJ422:Transposing is Even More Fun(Polya)
- Selenium学习四——利用Python爬取网页多个页面的表格数据并存到已有的excel中
- JSP中相对路径与绝对路径问题
- HDU 4272 LianLianKan
- 高并发系统限流
- OTT系统和IPTV系统不一样吗?有什么区别?
- 关于字符串
- 关于项目的一点点总结,签到返利日历的实现
- CAN通信中地址设置的问题
- $.Deferred(),for循环内异步请求问题的解决办法
- 三个字符串s1, s2, s3, 现要求你判断s3是否由s1和s2交错组成的
- 1004: A+B(基本输入输出4)