程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> 關於C++ >> Codeforces Round #167 (Div. 1)B

Codeforces Round #167 (Div. 1)B

編輯:關於C++
//對x從小到大排序
//開一個數組equal,存入一段相同的x的值
//那麼ans = equal[1]! * equal[2]! ....
//然後在除以沒一段相同x中的y相同的數的階乘
//由題意可知,開(xi == xj),(yi == yj)的最多只有兩個
//可以記錄下(xi == xj) ,(yi == yj)的對數,
//在計算的時候可以對偶數除2就行
#include
#include
#include
#include
using namespace std ;
const int maxn = 200010 ;
typedef __int64 ll ;
struct node
{
int x ,y;
}a[maxn] ;
bool cmp(struct node a ,struct node b)
{
if(a.x == b.x)
return a.y < b.y;
return a.x < b.x;
}
int equal_x[maxn] ;
int main()
{
int n ,m ;
while(~scanf("%d" ,&n))
{
for(int i = 1;i <= 2*n ;i++)
{
scanf("%d" ,&a[i].x) ;
a[i].y = i%n;
}
scanf("%d" ,&m) ;
sort(a+1 ,a+1+2*n , cmp);
int len_x = 0 ,len_y = 0;
for(int i = 1;i <= 2*n ;i++)
{
if(a[i].x == a[i-1].x)
{
if(a[i].y == a[i-1].y)
len_y++ ;
equal_x[len_x]++;
if(i == 2*n) len_x++;
}
else len_x++;
}
ll ans = 1;
for(int i = 0;i < len_x;i++)
{
for(int j = 1;j <= equal_x[i] ;j++)
{
if(len_y &&(j+1)%2 == 0)
{
ans = (ans * (ll)((j+1)/2)) % m;
len_y--;
}
else ans = (ans * (ll)(j+1)) % m;
}
}
printf("%I64d\n" ,ans) ;
}
return 0;
}



























  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved