2012 ACM/ICPC Asia Regional Changchun Online-LianLianKan

简介: 题意:类似于我们玩的连连看,从上往下,6个水果内如果有相同的2个水果则可以消去,直至水果被消完,输出1,或是找不到可以消去的水果,输出0。

LianLianKan

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


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

 



  2

1 1

3

1 1 1

2

1000000 1


Sample Output


 


  1

0

0

 

题意:类似于我们玩的连连看,从上往下,6个水果内如果有相同的2个水果则可以消去,直至水果被消完,输出1,或是找不到可以消去的水果,输出0。


思路:数据顶多1000个,直接暴力过。


#include<stdio.h>
int main()
{
    int a[1111];
    int n,i,j;
    while(scanf("%d",&n)!=EOF)
    {
        for(i=0;i<n;i++)
            scanf("%d",&a[i]);
        if(n%2) //因为每次只能消去2个,所以奇数个水果必然消不完
        {
            printf("0\n");
            continue;
        }
        int flag=n;
        while(flag>0)
        {
            int hash=0;
            for(i=0;i<n;i++)
            {
                if(a[i]!=-1)
                {
                    int num=0;
                    for(j=i+1;j<n;j++)
                    {
                        if(num>4) //6个水果内找不到2个相同的
                            break;
                        if(a[j]==a[i])
                        {
                            a[j]=-1; //消去的水果进行标记
                            a[i]=-1; //消去的水果进行标记
                            hash=1; //输出标记
                            flag-=2; //总水果数对应的减去2
                            break;
                        }
                        else
                        {
                            if(a[j]!=-1)
                                num++;
                        }
                    }
                }
                if(hash==1)
                    break;
            }
            if(hash==0)
            {
                printf("0\n");
                break;
            }
        }
        if(flag==0)
            printf("1\n");
    }
    return 0;
}
相关文章
2021 ICPC Asia Regionals Online Contest (II) Problem G. Limit
2021 ICPC Asia Regionals Online Contest (II) Problem G. Limit
The Preliminary Contest for ICPC China Nanchang National Invitational H题 Coloring Game
The Preliminary Contest for ICPC China Nanchang National Invitational H题 Coloring Game
96 0
《Six Major Changes in Science and Technology Reshaping the Retail Industry》电子版地址
Six Major Changes in Science and Technology Reshaping the Retail Industry
82 0
《Six Major Changes in Science and Technology Reshaping the Retail Industry》电子版地址
|
机器学习/深度学习 BI
2020-2021 ACM-ICPC, Asia Seoul Regional Contest L. Two Buildings (决策单调性 分治)
2020-2021 ACM-ICPC, Asia Seoul Regional Contest L. Two Buildings (决策单调性 分治)
135 0
2020-2021 ACM-ICPC, Asia Seoul Regional Contest L. Two Buildings (决策单调性 分治)
2012 ACM/ICPC Asia Regional Tianjin Online-Faulty Odometer
题意:有个特殊汽车的行程表,每逢数字3和8会跳过直接到4和9,给你一个行程表的示数,求汽车实际走的路程。
137 0
HDOJ 1064 Financial Management
HDOJ 1064 Financial Management
90 0
6 Major Changes in Science and Technology Reshaping the Retail Industry
As the transformation of the retail industry deepens, consumers are now at the center of the entire industry ecosystem.
3825 0
6 Major Changes in Science and Technology Reshaping the Retail Industry
|
安全
Navigating Through China's Cybersecurity Legislation
Are you expanding your business to China? Discover how Alibaba Cloud's platform helps compliance with China's cybersecurity legislation.
2837 0
Navigating Through China's Cybersecurity Legislation