前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >2012 ACM/ICPC Asia Regional Changchun Online-LianLianKan

2012 ACM/ICPC Asia Regional Changchun Online-LianLianKan

作者头像
Java架构师必看
发布2021-05-14 10:30:53
2720
发布2021-05-14 10:30:53
举报
文章被收录于专栏:Java架构师必看

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

代码语言:javascript
复制
   2
1 1
3
1 1 1
2
1000000 1

Sample Output

代码语言:javascript
复制
   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;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档