LianLianKan

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
 水题飘过,不在罗嗦。。。
#include<iostream>
#include<stdio.h>
#include<map>
using namespace std;
int n,p[1000];
int main()
{
    int i,flag;
    while(scanf("%d",&n)!=EOF)
    {
        map<int,int> mp;
        flag=0;
        for(i=0;i<n;i++)
        {
            scanf("%d",&p[i]);
        }
        if(n&1) puts("0");
        else
        {
            for(i=0;i<n;i++)
            {
                mp[p[i]]++;
            }
        map<int,int>::iterator it;
        for(it=mp.begin();it!=mp.end();it++)
        {
            if(it->second&1)  flag=1;
        }
        if(flag==1) puts("0");
        else puts("1");
        }
    }
    return 0;
}
posted @ 2013-06-18 08:56  forevermemory  阅读(374)  评论(0编辑  收藏  举报