2012 ACM/ICPC Asia Regional Changchun Online

来源:互联网 发布:python wmi 编辑:程序博客网 时间:2024/04/30 08:36

1006

LianLianKan

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0


Problem Description
I like playing game with my friends, although sometimes look 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 the 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 wisdom among my friends, 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 5.
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 integers 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


英语烂也有好处啊,less than 是小于,一直以为是小于等于。一不小心就ac了,rp吼吼,简单贪心模拟水水的过了,貌似后来看了下还是偶们学校第一个ac的吼吼,rp万岁

然后剩下四个半小时一题没做出来....实力不济(Y-Y)

#include<stdio.h>#include<string.h>#define begin freopen("a.in","r",stdin); freopen("a.out","w",stdout);#define end fclose(stdin); fclose(stdout);int a[1010],b[1010];int main(){ int i,n,j,dis,top,f; while (scanf("%d",&n)!=EOF) { memset(b,0,sizeof(b)); for (i=1;i<=n;i++) {  scanf("%d",&a[i]);  b[i]=1; } if (n%2) printf("0\n"); else { top=1; f=0; while (top<n) {  for (i=top;i<=n;i++)  if (b[i]==1)  {   j=i; dis=0;   while (dis<=5&&j<=n)   {    if (b[j+1]==1)    {     ++dis;     if (a[i]==a[j+1]&&dis<5) {b[i]=0;b[j+1]=0;f=1;}    }    ++j;    if (f) break;   }  }  if (f) f=0;    else  break;  while (b[top]==0&&top<=n) ++top; } f=1; for (i=1;i<=n;i++) if (b[i]){f=0; break;} printf("%d\n",f); } } return 0;}