HDU 4272 LianLianKan(模拟)
来源:互联网 发布:java客户端socket通信 编辑:程序博客网 时间:2024/05/06 13:17
LianLianKan
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3292 Accepted Submission(s): 996
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
Source
2012 ACM/ICPC Asia Regional Changchun Online
题意:给出一个序列,其中距离不超过6的两个相同的数字可以消除掉,现在问把能消除的全部消除之后序列中是不是还有数字,有的话输出0,没有的话输出1
思路:按照题意模拟一遍然后判断是不是为空就可以了
点击打开链接
#include<iostream>#include<algorithm>#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<queue>#include<stack>#include<vector>#include<map>using namespace std;int n;__int64 a[10010];int v[10010];__int64 b[10010];int main() { while(scanf("%d",&n)!=EOF) { for(int i=1; i<=n; i++) { scanf("%I64d",&a[i]); } memset(v,0,sizeof(v)); int t = 0; int flag; for(int i=1; i<=n; i++) { int pt = t; flag = 0; if(v[i] == 1){continue; } for(int k=1; k<=t; k++) { if(a[i] == b[k]) { for(int pi=k; pi<t; pi++) { b[pi] = b[pi+1]; } t--; flag = 1; } } if(pt == t) { int pf = 0; for(int j=i+1; j<=i+5 && j<=n; j++) { if(a[i] == a[j]) { v[i] = 1; v[j] = 1; pf = 1; break; } } if(pf == 0) { b[++t] = a[i]; } } } if(t == 0) { printf("1\n"); } else { printf("0\n"); } } return 0;}
0 0
- HDU 4272 LianLianKan(模拟)
- hdu 4272 LianLianKan(模拟dfs+map)
- 【HDU】4272 LianLianKan(DFS)
- HDOJ 4272 LianLianKan(简单模拟)
- HDU 4272 LianLianKan(贪心!!!!!)
- hdu 4272 LianLianKan
- hdu 4272 LianLianKan
- HDU 4272 lianliankan
- HDU 4272 LianLianKan
- Hdu 4272 LianLianKan(贪心+链表)
- HDU 4272 LianLianKan 状态压缩DP
- HDU 4272 LianLianKan 记忆化搜索
- HDU 4272 LianLianKan DFS+map优化
- LianLianKan
- LianLianKan
- lianliankan
- LianLianKan
- HDU 4272LianLianKan 2012长春网络赛F题(思维) 暴力,dfs可以水过,正解是状态压缩dp
- Leetcode: Implement Stack using Queues
- HTML+CSS笔记
- 分组密码SM4算法的代码实现
- Eclipse常用快捷键
- C语言判断大小端对齐
- HDU 4272 LianLianKan(模拟)
- minAreaRect函数
- maven学习
- 打开绘图工具mspaint.exe
- Sublime Text2.0.2注册码
- iOS原生分享UIActivityViewController
- java项目部署linux(ubuntu)常见问题
- 安卓源码总体结构(2)基础知识汇总
- ORA-00923: 未找到要求的 FROM 关键字