B - 皇马

来源:互联网 发布:php输出当前时间 编辑:程序博客网 时间:2024/05/28 04:56

Description

There are n swords of different weights Wiand n heros of power Pi.

Your task is to find out how many ways the heros can carry the swords so that each hero carries exactly one sword.

Swords

Here are some rules:

(1) Every sword is carried by one hero and a hero cannot carry a sword whose weight is larger than his power.

(2) Two ways will be considered different if at least one hero carries a different sword.

Input

The first line of the input gives the number of test cases T(1 ≤ T ≤ 50).

Each case starts with a line containing an integer n (1 ≤ n ≤ 105denoting the number of heros and swords.

The next line contains n space separated distinct integers denoting the weight of swords.

The next line contains n space separated distinct integers denoting the power for the heros.

The weights and the powers lie in the range [1, 109].

Output

For each case, output one line containing "Case #x: " followed by the number of ways those heros can carry the swords.

This number can be very big. So print the result modulo 1000 000 007.

题意:t组数据,有n把剑和n个人,每把剑都有自己的重量,每个人都有自己的能力,只有此人的能力大于等于此剑的重量才能拿起这把剑,把n把剑分给n个人,每人都能拿起各自的剑,求总共有几种分法。

Sample Input

3

5

1 2 3 4 5

1 2 3 4 5

2

1 3

2 2

3

2 3 4

6 3 5

Sample Output

Case #1: 1

Case #2: 0

Case #3: 4

#include <cstdio>#include <algorithm>using namespace std;int w[100002],p[100002];int main(){    int T,n;    scanf("%d",&T);    for(int k=1; k<=T; k++)    {        scanf("%d",&n);        for(int i=0; i<n; i++)            scanf("%d",&w[i]);        for(int i=0; i<n; i++)            scanf("%d",&p[i]);        sort(w,w+n);        sort(p,p+n);        long long int cnt=1;        int j=0;        for(int i=0; i<n; i++)        {                    for(;j<n;j++)                    {                       if(w[j]>p[i])                       break;;                    }                    cnt=cnt*(j-i)%1000000007;        }        printf("Case #%d: %lld\n",k,cnt);    }    return 0;}


0 0
原创粉丝点击