AT2271 solution to a problem [Lining Up]

Title Translation:

 

There are number N 1-N number of individuals, they all remember "the absolute value of the difference between the number of persons queuing own left and right of the line of their own," according to their report, to "your own i left the number and arrangement the number of his right arrangement of the absolute value of "Ai difference. Please According to their report, obtained the original arrangement There are several ways. However, because the answer sometimes become very large, please to 10 ^ 9 + 7 modulo. In addition, their report may be wrong, there is no possible arrangement method, then please output 0.

range:

1≦N≦10^5; 0≦Ai≦N−1.

 

 

In fact, the meaning of problems can be transformed in such a way, there is a sequence disorder, post requires you to meet certain sort judge whether the law of increasing -

 

Do not understand?

 

We can think, everyone's position is uncertain, but they have a relative position, for example:

 

1 1 1 1 1 1 1 1 1 1 1

 

I saw the crooked '1' it (you must have seen the right), we can know the meaning of the questions here Ai = | 2-8 | = 6

It does this:

 

1 1 1 1 1 1 1 1 1 1 1

 

Ai here = | 8-2 | = 6

 

Because each point Ai is given, we can know -


1 1   1 1 1 1 1   1 1

 

When arranged in two equal points Ai are interchangeable, the total program should be 2 ^ (n / 2). If n is odd, i.e., in the middle of the most personal, on its Ai is 0, so it does not interchangeable positions, n / 2 it just give it up.

We look at the set of sample:

5

24402

answer is 4, is just 2 ^ (n / 2) number. But why would the next set of sample output 0 it? Not necessarily because it is right to Ai, then you need to judge. Judgment is very simple, carefully point you will find that the smaller the more people in the middle of the Ai, until the middle of most, may be only 0 or 1, and then push it a little bit, you will find:

0 2 2 4 4 8 8……


1 1 3 3 5 5 7 7……

 

Yes, that is said at the beginning of the increasing sequence! We just give input Ai row a sequence in the correct sequence comparison with eleven on the line

Weak weak to offer Tacca code:


#include<stdio.h>
#include<algorithm>
using namespace std;
const int mod=1e9+7;
int num[100005],a[100005];
void init(int x)
{
    if(x%2==0)
        for(int i=1;i<=x;i+=2) 
        {
            a[i]=i;
            a[i+1]=a[i];
        }
    else
        for(int i=2;i<=x;i+=2)
        {
            a[i]=i;
            a[i+1]=a[i];
        }

}
int main()
{
    int n,k=1;
    scanf("%d",&n);
    init(n);
    for(int i=1;i<=n;i++)
        scanf("%d",&num[i]);
    sort(num+1,num+1+n);
    for(int i=1;i<=n;i++)
        if(a[i]!=num[i])
        {
            printf("0");
            return 0; 
        }

    long long ans=1;
    n/=2;
    while(n--)
        ans=ans*2%mod;
    printf("%lld",ans);
    return 0;
}

 

 I recommend Los Valley: https://www.luogu.org/space/show?uid=88557

 

Guess you like

Origin www.cnblogs.com/tfyzs/p/11618732.html