cf 167.div2 D.Dima and Two Sequences
2013-02-14 02:35
330 查看
今天的cf完全不在状态,A题10分钟才读懂题意。目测要掉rating了
这题题意很简单,就是按X升序排列会有多少种情况,一个排列组合的问题
设相同x的元素个数为Xi ,完全相同为2K(易知若完全相同有且仅有2个,比赛的时候就没想到这一点)
ans= ∑Xi!/2^k
之所以能在阶乘中除2^k,是因为k最大为n/2,而n!中的2的因子至少为n/2
这题题意很简单,就是按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); }
相关文章推荐
- CodeForces 272 D.Dima and Two Sequences(组合数学)
- Codeforces Round #167 (Div. 2) D. Dima and Two Sequences 排列组合
- [codeforces272D]Dima and Two Sequences
- cf 167.div2 E.Dima and Horses
- Codeforces 272D Dima and Two Sequences【思维+模拟】
- CF round167 Div1 C Dima and Horses
- CF Fox And Two Dots (DFS)
- CF 450 B Jzzhu and Sequences(矩阵快速幂)
- CF 366E Dima and Magic Guitar(最远哈密顿距离)
- cf B. Dima and Text Messages
- CF 510B(Fox And Two Dots-图上找环)
- CF 273C C. Dima and Horses
- CF10月25日比赛。(Dima and Text Messages)
- CF 366E - Dima and Magic Guitar 最远曼哈顿距离
- Codeforces Round #243 (Div. 1)——Sereja and Two Sequences
- Codeforces Round #243 (Div. 1)——Sereja and Two Sequences
- CF 305C ——Ivan and Powers of Two——————【数学】
- Jzzhu and Sequences - CF 450B 矩阵快速幂版
- cf D. Dima and Lisa (三素数定理_素数打表+判定)
- cf E. Dima and Magic Guitar