hdoj 4272 LianLianKan 数据太水

LianLianKan

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

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

Sample Output

1
0
0

 

题意

给你一个队列,然后每个子可以和距离为以内的子连接,然后这两个子都pop,然后问你,是否这个队列能够全部pop掉

题解

数据太水了,判一判子的个数是否为偶数,然后再判断是否每一类都是偶数,然后直接输出1,然后就A了= =

标答应该是一个状态压缩DP

LL a[maxn];
int vis[maxn];
int flag=0;
map<int,int> kiss;
int n;
void dfs(int nn,int cur)
{
    if(nn>n)
        return;
    if(vis[nn]==1)
        dfs(nn+1,cur);
    if(cur==n)
    {
        flag=1;
        return;
    }
    int m=nn;
    REP_1(i,5)
    {
        m++;
        while(1)
        {
            if(m>n)
                return;
            if(vis[m]==0)
                break;
            m++;
        }
        if(a[m]==a[nn])
        {
            vis[nn]=1;
            vis[m]=1;
            dfs(nn+1,cur+2);
            vis[nn]=0;
            vis[m]=0;
        }
    }
}
int main()
{
    while(RD(n)!=-1)
    {
        memset(vis,0,sizeof(vis));
        kiss.clear();
        REP_1(i,n)
        {
            RD(a[i]);
            kiss[a[i]]++;
        }
        if(n%2==1)
        {
            flag=0;
            printf("0\n");
            continue;
        }
        int flag2=1;
        REP_1(i,n)
        {
            if(kiss[a[i]]%2==1)
            {
                flag2=0;
                break;
            }
        }
        if(flag2==0)
        {
            printf("0\n");
            continue;
        }
        //dfs(1,0);
        cout<<"1"<<endl;
    }

}
时间: 2024-10-12 07:24:21

hdoj 4272 LianLianKan 数据太水的相关文章

ACM--次数最多--HDOJ 1032--The 3n + 1 problem--水(数据太弱)

HDOJ题目地址:传送门 The 3n + 1 problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 34456    Accepted Submission(s): 12454 Problem Description Problems in Computer Science are often classified as b

table中数据太长部分显示

<style type="text/css"> .etc{white-space:nowrap;text-overflow:ellipsis;overflow:hidden;width:200px;} </style> <table> <tr> <td><div class="etc" title="数据太长了怎么办,...部分显示">数据太长了怎么办,...部分显示<

解决持久化数据太大,单个节点的硬盘无法存储的问题;解决运算量太大,单个节点的内存、CPU无法处理的问题

需要学习的技术很多,要自学新知识也不是一件容易的事,选择一个自己比较感兴趣的会是一个比较好的开端,于是,打算学一学分布式系统. 带着问题,有目的的学习,先了解整体架构,在深入感兴趣的细节,这是我的计划. 首先得有问题,如果每日重复相同的工作,也不主动去学习,很难发现新的问题.不怕自己无知,就怕不知道自己无知,只有不断的学习,才会发现更多未知的知识领域! 带着问题出发 回到顶部 分布式要解决什么问题呢?解决持久化数据太大,单个节点的硬盘无法存储的问题:解决运算量太大,单个节点的内存.CPU无法处理

C# JavaScriptSerializer报错,json数据太长

ASP.NET平台中,用JavaScriptSerializer将返回的数据序列化,若返回的数据非常大,则可能会报如下错误: Exception information: Exception type: InvalidOperationException Exception message: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the st

解决前台展示的R表出数据太慢的方法

解决前台展示的R表出数据太慢的方法第一种方法1.业务逻辑处理后插入 _bak表 2._bak表 纯插入 R表 最后只剩 _bak表,R表 第二种方法1.业务逻辑处理后插入 dm表 2.dm表 纯插入 tmp表 2.R表 重命名为 _bak表 3.tmp表 重命名为 R表 4._bak表 重命名为 tmp表 最后只剩 dm表 ,tmp表,R表 总结: 重命名可能比插入更快,但包体可能因为重命名后表不存在而报错.如果不报错,第2种方法更快. 原文地址:https://www.cnblogs.com/

echart-折线图,数据太多想变成鼠标拖动和滚动的效果?以及数据的默认圈圈如何自定义圆圈的样式

1.数据太多怎么办???想拖拽,想滑动 dataZoom: [ { type: 'slider', } ] dataZoom: [ { type: 'inside',  }] 2.圈圈该怎么画?用图片,会导致点击图例在显示时,恢复了默认的圈圈(忽略颜色) 原文地址:https://www.cnblogs.com/snowbxb/p/11684661.html

HDOJ 2317. Nasty Hacks 模拟水题

Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3049    Accepted Submission(s): 2364 Problem Description You are the CEO of Nasty Hacks Inc., a company that creates small pieces of

Hdu 4272 LianLianKan(贪心+链表)

LianLianKan Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3080    Accepted Submission(s): 956 Problem Description I like playing game with my friend, although sometimes looks pretty naive. To

MySQL数据单个数据太大,导入不进去

mysql导入数据,navicat报错: 1 2 3 4 5 MySQL server has gone away Table Restored: act_ge_bytearray Rolling back... Finished - Stopped before completion -------------------------------------- 问题原因:导入的数据超过了mysql默认单个字段最大容量 #查看数据库中最大的单个文件容量 SHOW VARIABLES LIKE '