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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值