LianLianKan
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1815 Accepted Submission(s): 563
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.
![](https://i-blog.csdnimg.cn/blog_migrate/791b82e30179bc1b498d58e6ad7733d3.jpeg)
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
2 1 1 3 1 1 1 2 1000000 1
Sample Output
1 0 0
Source
Recommend
liuyiding
题目超坑!这个数据要过
10
122131111113
1才行,题目说的一点都不清
#include <iostream>
#include <stdio.h>
using namespace std;
struct node{
int father,next;
__int64 val;
}l[1050];
int top,tail;
int main()
{
int n,i,j,re;
bool flag;
while(scanf("%d",&n)!=EOF)
{
re=n;
top=0;
tail=n-1;
for(i=0;i<n;i++)
{
scanf("%I64d",&l[i].val);
l[i].father=i-1;
l[i].next=i+1;
}
if(n&1)
{
printf("0\n");
continue;
}
while(top!=tail&&re)
{
flag=true;
for(j=l[top].next,i=0;i<=6&&flag;i++,j=l[j].next)
{
if(l[top].val==l[j].val)
{
flag=false;
if(j==tail)//在最后
{
tail=l[j].father;
re=re-2;
break;
}
l[l[j].father].next=l[j].next;
l[l[j].next].father=l[j].father;
re=re-2;
break;
}
if(j==tail)
break;
}
if(flag)
break;
top=l[top].next;//头向后移
l[top].father=-1;
}
if(re)
{
printf("0\n");
}
else
{
printf("1\n");
}
}
return 0;
}