cf 167.div2 D.Dima and Two Sequences

简介:

    今天的cf完全不在状态,A题10分钟才读懂题意。目测要掉rating了

    这题题意很简单,就是按X升序排列会有多少种情况,一个排列组合的问题

    设相同x的元素个数为Xi  ,完全相同为2K(易知若完全相同有且仅有2个,比赛的时候就没想到这一点)

    ans= ∑Xi!/2^k

   之所以能在阶乘中除2^k,是因为k最大为n/2,而n!中的2的因子至少为n/2

/*
author:jxy
lang:C/C++
university:China,Xidian University
**If you need to reprint,please indicate the source**
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define INF 1E9
using namespace std;
struct node
{
    int x,y;
};
bool cmp(node a,node b)
{
    if(a.x!=b.x)return a.x<b.x;
    return a.y<b.y;
}
node org[200010];
long long fac(int n,int m,int &tt)
{
    long long ans=1;
    int i,t;
    for(i=1;i<=n;i++)
    {
        t=i;
        while(tt&&!(t&1)){t>>=1;tt--;}//除去2^k
        ans=(ans*t);
        if(ans>m)ans%=m;
    }
    return ans;
}
int main()
{
    int n,t;
    scanf("%d",&n);
    n*=2;
    int i,j,k;
    for(i=k=1;i<=n;i++,k++)
    {
        scanf("%d",&t);
        org[i].x=t;
        org[i].y=k;
        if(k==n/2)k=0;
    }
    int m;
    scanf("%d",&m);
    sort(org+1,org+n+1,cmp);
    long long ans=1;
    int tt=0;
    for(i=1;i<=n;i++)
    {
        t=1;
        j=1;
        while(i<=n&&org[i].x==org[i+1].x)
        {

            if(org[i].y==org[i+1].y)j++;
            else
            {
                if(j>1)tt++;
                j=1;
            }
            i++;t++;
        }
        if(j>1)tt++;
        if(t>1)
        {
            ans=(ans*(fac(t,m,tt)));
            if(ans>=m)ans%=m;
        }
    }
    printf("%I64d\n",ans);
}


目录
相关文章
|
SQL Oracle 关系型数据库
BC范式(Boyce-Codd Normal Form,BCNF)
BC范式(Boyce-Codd Normal Form,BCNF)是关系数据库设计中的一个规范化级别,它建立在第三范式(3NF)的基础上,通过进一步消除非主属性对于候选键的部分函数依赖来消除主属性对于候选键的传递依赖
763 1
成功解决but is 0 and 2 (computed from start 0 and end 9223372 over shape with rank 2 and stride-1)
成功解决but is 0 and 2 (computed from start 0 and end 9223372 over shape with rank 2 and stride-1)
HDOJ 1092 A+B for Input-Output Practice (IV)
HDOJ 1092 A+B for Input-Output Practice (IV)
124 0
2.Text input and output
文本的输入和输出 输出 要在屏幕上输出文本你需要这样一行代码: print("Hello World") 如果输出多行,要添加符号“\n”: print("Hello World\nThis is a message") 输出值的话: x = 3 print(x) 输出多行数值: ...
627 0

热门文章

最新文章