CODEFORCES 272D Dima and Two Sequences <排列组合>
来源:互联网 发布:cookie登录 php 编辑:程序博客网 时间:2024/06/05 01:38
传送门:http://codeforces.com/problemset/problem/272/D
题意:给你两个串(a1,1),(a2,2),...,(an,n)和(b1,1),(b2,2),...,(bn,n)。把两个串放在一个集合里面,按照前一个参数排序,问有多少种排列方法?
分析:排列组合
对于(x,y),对于同一个x可能有许多对应的y,但y数一样中相同的最多两个。对于x分段求组合数,之后连乘,段中,有几对相同的就除以多少个2。(排列组合中去重而已)
code 1
#include<iostream>#include<map>#include <vector>#include <queue>#include <algorithm>#define ll long longusing namespace std;vector<pair<int,int> > pq;int main(){ int n,d; ll m; ll ans = 1; cin >> n; for(int i=1;i<=n;i++) { scanf("%d",&d); pq.push_back(make_pair(d,i)); } for(int i=1;i<=n;i++) { scanf("%d",&d); pq.push_back(make_pair(d,i)); } cin >> m; sort(pq.begin(),pq.end()); ll dd = 0; for(int i=0;i< 2*n;i++) { int f = pq[i].first; int s = pq[i].second; i++; int f2 = pq[i].first; int s2 = pq[i].second; while(f == f2) { if(s == s2) { dd++; } f = f2; s = s2; i++; f2 = pq[i].first; s2 = pq[i].second; } if(i == 2*n-1) break; i--; } for(int i=0;i< 2*n;i++) { int f = pq[i].first; i++; int f2 = pq[i].first; ll a = 1; int x,tmp = 1; while(f == f2) { tmp++; x = tmp; while(dd&&x%2==0) { dd --; x/=2; } a = (a*x)%m; f = f2; i++; f2 = pq[i].first; } ans = ans*a%m; if(i == 2*n-1) break; i--; } printf("%I64d\n",ans); return 0;}
code 2
#include<bits/stdc++.h>using namespace std;typedef long long ll;const int MAX=1e5+9;ll a[MAX],n,m,b[MAX],cnt,ans=1;map<ll,ll> mp;int main(){cin>>n;for (int i=0;i<n;i++) cin>>a[i],mp[a[i]]++;for (int i=0;i<n;i++) cin>>b[i],cnt+=(b[i]==a[i]),mp[b[i]]++;cin>>m;for (auto i:mp)for (int j=1;j<=i.second;j++){ll x=j;while (cnt>0 && x%2==0) x/=2,cnt--;ans=ans*x%m;}cout<<ans%m;}
0 0
- CODEFORCES 272D Dima and Two Sequences <排列组合>
- Codeforces 272D Dima and Two Sequences【思维+模拟】
- cf 167.div2 D.Dima and Two Sequences
- [codeforces272D]Dima and Two Sequences
- Codeforces 208 div2 D. Dima and Hares
- CodeForces 366D Dima and Trap Graph
- Codeforces 400 D. Dima and Bacteria
- CodeForces 400D Dima and Bacteria
- codeforces 400D - Dima and Bacteria
- Codeforces 358 D. Dima and Hares
- Codeforces Round #324 D Dima and Lisa
- codeforces 584D Dima and Lisa
- CodeForces 584D Dima and Lisa
- Codeforces 584D Dima and Lisa 【数学】
- CodeForces 584D Dima and Lisa
- Codeforces 358D Dima and Hares【dp】
- CodeForces 584D - Dima and Lisa(数论)
- Codeforces 358D Dima And Hares DP
- javaweb--Tomcat>>更改Tomcat的默认配置
- js进阶学习之--闭包的理解
- 论高中“集”与C语言“数组”的关系
- XCode 快捷键
- 60. Permutation Sequence
- CODEFORCES 272D Dima and Two Sequences <排列组合>
- Cocos网络访问——代理模式(2)
- Hibernate应用的优化
- 二叉树
- POJ 1961 Period(KMP)
- 【CQYZ-vijos】P1333 舞伴的搭配(贪心算法)
- C++中虚函数解析
- 日期类问题
- 分享一个圆角自定义的漂亮AlertDialog