Lining Up

问题 H: Lining Up

时间限制: 1 Sec  内存限制: 128 MB
提交: 45  解决: 30
[提交][状态][讨论版][命题人:admin]

题目描述

There are N people, conveniently numbered 1 through N. They were standing in a row yesterday, but now they are unsure of the order in which they were standing. However, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person. According to their reports, the difference above for person i is Ai.
Based on these reports, find the number of the possible orders in which they were standing. Since it can be extremely large, print the answer modulo 109+7. Note that the reports may be incorrect and thus there may be no consistent order. In such a case, print 0.

Constraints
1≤N≤105
0≤Ai≤N?1

输入

The input is given from Standard Input in the following format:
N
A1 A2 … AN

输出

Print the number of the possible orders in which they were standing, modulo 109+7.

样例输入

5
2 4 4 0 2

样例输出

4

提示

There are four possible orders, as follows:
·2,1,4,5,3
·2,5,4,1,3
·3,1,4,5,2
·3,5,4,1,2

#include <iostream>
#include <cstdio>

using namespace std;

int a[100005]= {0};
int n;
int pd1()
{
    for(int i=1; i<=n-1; i+=2)
    {
        if(a[i]!=2)
        {
            return 0;
        }
    }
    return 1;
}
int pd2()
{
    if(a[0]!=1)
        return 0;
    int t = n/2;
    for(int i=1; i<=t; i++)
    {
        if(a[i*2]!=2)
        {
            return 0;
        }
    }
    return 1;
}
int main()
{

    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        int x;
        scanf("%d",&x);
        a[x]++;
    }
    if(n%2==0)
    {
        int flag = pd1();
        if(flag==0)
            printf("0");

        else
        {
            long long int t = 1;
            int p = n/2;
            for(int i=0; i<p; i++)
            {
                t*=2;
                t%=1000000007;
            }
            printf("%lld",t);
        }
    }
    else
    {
        int flag = pd2();
        if(flag==0)
            printf("0");
        else
        {
            long long int t = 1;
            int p = n/2;
            for(int i=0; i<p; i++)
            {
                t*=2;
                t%=1000000007;
            }
            printf("%lld",t);
        }
    }
}

规律题 奇数偶数分情况讨论

样例

7
6 4 0 2 4 0 2   输出:0;

8
7 5 1 1 7 3 5 3    输出:16;

原文地址:https://www.cnblogs.com/hao-tian/p/9119236.html

时间: 2024-10-18 17:45:33

Lining Up的相关文章

Hdoj 1432 Lining Up 【叉积】

Lining Up Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1094    Accepted Submission(s): 307 Problem Description ``How am I ever going to solve this problem?" said the pilot. Indeed, the pilot

UVALive5379 UVA270 Lining Up

Regionals 1994 >> North America - East Central NA 问题链接:UVALive5379 UVA270 Lining Up. 题意简述:输入n,输入n个整数对,即n个坐标点,问最多共线点数是多少. 问题分析:用暴力法解决这个问题,好在计算规模不算大. 程序中,判断共线时,使用的是乘法,没有用除法,可以保证精确的计算结果. 特别需要说明的是,这个问题虽然与POJ1118 HDU1432 Lining Up是相同的问题,但是数据输入格式不一样,需要特别处

POJ1118 HDU1432 Lining Up

问题链接:POJ1118 HDU1432 Lining Up. 题意简述:输入n,输入n个整数对,即n个坐标点,问最多共线点数是多少. 问题分析:用暴力法解决这个问题,好在计算规模不算大. 程序中,判断共线时,使用的是乘法,没有用除法,可以保证精确的计算结果. AC的C语言程序如下: /* POJ1118 HDU1432 Lining Up */ #include <stdio.h> #define MAXN 700 struct { int x, y; } p[MAXN]; /* point

Lining Up(在一条直线上的最大点数目,暴力)

Lining Up Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1274    Accepted Submission(s): 366 Problem Description ``How am I ever going to solve this problem?" said the pilot.  Indeed, the pilo

uva 270 Lining Up (几何)

uva 270 Lining Up ``How am I ever going to solve this problem?" said the pilot. Indeed, the pilot was not facing an easy task. She had to drop packages at specific points scattered in a dangerous area. Furthermore, the pilot could only fly over the a

uva270 - Lining Up(暴力)

题目:uva270 - Lining Up 解题思路:对于每个点都计算一下,它与其他点的斜率,这样就可以判断与这个点在同一条直线的点.每个点都这样做,维护最大值就可以了. 注意斜率不存在的情况. 找相同斜率的时候用了multiset. 代码: #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <set> using namespace

POJ 1018 &amp; HDU 1432 Lining Up 【简单几何】

Lining Up Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 24786   Accepted: 7767 Description "How am I ever going to solve this problem?" said the pilot. Indeed, the pilot was not facing an easy task. She had to drop packages at spe

Lining.js - 为CSS提供 ::nth-Line 选择器功能

在CSS中,我们使用 ::first-line 选择器来给元素第一行内容应用样式.但目前还没有像 ::nth-line.::nth-last-line 甚至 ::last-line 这样的选择器.实际上这期选择器在某些情况下是非常有用的,Lining.js 提供了这样的功能. 在线演示      插件下载 您可能感兴趣的相关文章 网站开发中很有用的 jQuery 效果[附源码] 分享35个让人惊讶的 CSS3 动画效果演示 十分惊艳的8个 HTML5 & JavaScript 特效 Web 开发

UVA Lining Up (一条直线上最多的点数)

Description  Lining Up  ``How am I ever going to solve this problem?" said the pilot. Indeed, the pilot was not facing an easy task. She had to drop packages at specific points scattered in a dangerous area. Furthermore, the pilot could only fly over