LianLianKan[HDU4272]
LianLianKan
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1760 Accepted Submission(s): 547
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.
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)
Output
For each test case, output “1” if I can pop all elements; otherwise output “0”.
Sample Input
2
1 1
3
1 1 1
2
1000000 1
Sample Output
1
0
0
Source
2012 ACM/ICPC Asia Regional Changchun Online
Recommend
liuyiding
想了半天不知咋办,在网上搜了一下原来这样也可以...
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
using namespace std;
#define MAXN 1010
#define INF 0xFFFFFFF int n;
vector<int>v; void solve() {
int flag, i;
vector<int>::iterator it1, it2;
while () {
flag = ;
if (v.size() <= ) break;/*只有一个元素的肯定不行*/
it1 = v.begin();
for (; it1 != v.end(); it1++) {
for (it2 = it1 + , i = ; i < && it2 != v.end(); i++ , it2++) {
if (*it1 == *it2) {
v.erase(it1);/*这里删除了it1后it2会往回移动一个*/
v.erase(it2-);/*所以由上面的可知这里删除it2-1位置*/
flag = ; break;
}
}
if (flag) break;
}
if (!flag || !v.size()) break;/*如果flag为0或v为空退出*/
}
if (v.size()) printf("0\n");
else printf("1\n");
} int main() {
//freopen("input.txt", "r", stdin);
int tmp;
while (scanf("%d", &n) != EOF) {
v.clear();
for (int i = ; i < n; i++) {
scanf("%d", &tmp);
v.push_back(tmp);/*全部插入vector*/
}
solve();
}
return ;
}
LianLianKan[HDU4272]的更多相关文章
- HDU-4272 LianLianKan
http://acm.hdu.edu.cn/showproblem.php?pid=4272 据说是状态压缩,+dfs什么什么的,可我这样也过了,什么算法都是浮云 ,暴力才是王道.我也归类为状态压缩, ...
- hdoj 4272 LianLianKan 数据太水
LianLianKan Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 4272 LianLianKan 状态压缩
LianLianKan Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- LianLianKan - HDU 4272(状态压缩)
题目大意:有一列数据,可以从最上面的开始连接下面相同的元素,然后消除,不过距离不能超过6,询问最后能不能消除完整个数列. 分析:首先讨论一点最远能消除的地方,比如点的位置是x,如若想要消除x+1位置处 ...
- HDU 4272 LianLianKan (状压DP+DFS)题解
思路: 用状压DP+DFS遍历查找是否可行.假设一个数为x,那么他最远可以消去的点为x+9,因为x+1~x+4都能被他前面的点消去,所以我们将2进制的范围设为2^10,用0表示已经消去,1表示没有消去 ...
- LianLianKan HDU - 4272 状压dp
题意:长度为n(n<=1000)的栈,栈顶元素可以与下面1~5个数中相同的元素消去,问最后能都完全消去. 题解: 比如这个序列12345678910112这个位置的最远可匹配位置能到11为什么呢 ...
- HDU 4272 LianLianKan(状压DP)题解
题意:一个栈,每次可以选择和栈顶一样的数字,并且和栈顶距离小于6,然后同时消去他们,问能不能把所有的数消去 思路:一个数字最远能消去和他相距9的数,因为中间4个可以被他上面的消去.因为还要判断栈顶有没 ...
- HDU4272LianLianKan(dfs)
Problem Description I like playing game with my friend, although sometimes looks pretty naive. Today ...
- JavaScript编写连连看
这几天写题比较少,做了一下网页设计的期末大作业.搞了个连连看,核心代码和hdu 1175那个题目一样. 越来越觉得学ACM是十分有用的,软件的核心是数据结构和算法,学会了DFS,连连看就水到渠成了. ...
随机推荐
- Android 将可以按地点自动启动应用程序
导读Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导及开发.尚未有统一中文名称,中国大陆地区较多人使用“安 ...
- 用Prime31实现Google Play In-App-Blling
Android开发者想在海外赚钱,接入Google Play是不二选择,然而一堆英文文档对于像我这样的英语四级都木有过的可谓是苦恼之极.近段时间因工作需要研究了Unity接入Google Play的整 ...
- 架设基于StrongSwan的L2tp/IPSec VPN服务器
架设基于StrongSwan的L2tp/IPSec VPN服务器 参考: http://agit8.turbulent.ca/bwp/2011/01/setting-up-a-vpn-server-w ...
- Moebius集群:SQL Server一站式数据平台
一.Moebius集群的架构及原理 1.无共享磁盘架构 Moebius集群采用无共享磁盘架构设计,各个机器可以不连接一个共享的设备,数据可以存储在每个机器自己的存储介质中.这样每个机器就不需要硬件上的 ...
- Cannot change version of project facet Dynamic web module to 2.5
在工程目录下有一个.settings文件夹,打开org.eclipse.wst.common.project.facet.core.xml做如下修改:<installed facet=" ...
- 开博一周总结与随谈[thinking of writing blog for one week]
8天前,就是5月19号,突发奇想,觉得应该开个博客记录下自己的学习笔记和心得,更重要的是做个自我梳理和总结.大致看了下国内的博客,最后选定cnblogs.之所以选则cnblogs是因为平时搜到不少好文 ...
- Java入门的程序汇总
Java入门的基础程序,虽然很简单,也要多练习,下面有重点的总结一下 1.HelloWorld这个不说了 2.常量与变量部分 基本数据类型使用 public class Javashujuleixin ...
- [Android Pro] 通过IMSI判断手机是移动、联通、电信
TelephonyManager telManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); /** 获取 ...
- js 带省略号的分页源码及应用实例
一.js:pagination.js /*--说明分页div id为:changpage*/var eachPageDataNum = 10;//每页显示记录数var nowPage = 1;//当前 ...
- jquery 展开折叠菜单
jquery 展开折叠菜单 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <ht ...