周赛一 ACdream 1199 排列组合
2015-09-07 20:20
302 查看
Description
There are n swords of different weights Wiand n heros ofpower
Pi.
Your task is to find out how many ways the heros can carry the swords so that each hero carries exactly one sword.
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 ≤ 105)
denoting 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.
Sample Input
Sample Output
There are n swords of different weights Wiand n heros ofpower
Pi.
Your task is to find out how many ways the heros can carry the swords so that each hero carries exactly one sword.
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 ≤ 105)
denoting 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.
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<iostream> #include<cstring> #include<cstdio> #include<cstdlib> #include<algorithm> using namespace std; int p[100010]; int T,n; int a[100010]; int main() { while(~scanf("%d",&T)) { int Case=0; while(T--) { Case++; scanf("%d",&n); for(int i=0; i<n; ++i) scanf("%d",&a[i]); for(int j=0; j<n; ++j) scanf("%d",&p[j]); sort(a,a+n); sort(p,p+n); long long sum=1; int j=0; for(int i=0;i<n;i++) //组合数 求排列组合的种类 { while(j<n&&a[j]<=p[i])j++; sum=sum*(j-i)%1000000007; } printf("Case #%d: %lld\n",Case,sum%1000000007); } } } /* struct node { int power; int num; } p[100010]; int T,n; int a[100010]; int cmp(node p1,node p2) { return p1.power<p2.power; } int main() { while(~scanf("%d",&T)) { int Case=0; while(T--) { Case++; scanf("%d",&n); for(int i=0; i<n; ++i) scanf("%d",&a[i]); for(int j=0; j<n; ++j) { scanf("%d",&p[j].power); p[j].num=0; } sort(a,a+n); sort(p,p+n,cmp); int j=0; for(int i=0; i<n; ++i) //组合数 { if(i==0) { for(; j<n; j++) { if(p[i].power>=a[j]) p[i].num++; else break; } } else { if(p[i-1].power==p[i].power) { p[i].num=p[i-1].num-1; } else { p[i].num=p[i-1].num; for(; j<n; j++) { if(p[i].power>=a[j]) p[i].num++; else { p[i].num-=1; break; } } if(j==n) p[i].num-=1; } } } long long int sum=1; for(int i=0; i<n; i++) { sum*=p[i].num%1000000007; sum%=1000000007; //勿漏<span id="transmark"></span> if(sum==0) break; } printf("Case #%d: %lld\n",Case,sum%1000000007); } } } */
相关文章推荐
- 第一章 绪论
- 多态和虚表
- Android 数据存储:五大存储之File存储(内部存储与外部存储)
- mysql数据库创建、删除数据库
- window获取系统默认浏览器并打开相应的网址
- Processing 教程(7) - 平移、旋转、放缩
- 聊天服务器-客户端
- 高效开发之SASS篇
- 后缀数组 (倍增法) 个人理解
- Find them, Catch them---poj1703(并查集)
- ERROR: HHH000388: Unsuccessful: create table right (right_code varchar(255) not null auto_increment,
- hadoop配置好之后启服务,jps能看到datanode进程,可是后台的datanode日志有如下错误,且50070端口上也是没有活的节点
- 大数据之nutch
- Vbs脚本执行不同版本的Windows OS激活任务(MAK&KMS激活)
- 数据结构与算法(C#版)第二章 C#语言与面向对象技术(上)V1.0
- Fragment实例,数据存储,数据库SQLite
- unique函数
- Hello JSP!——<jsp:plugin>、<jsp:params>、<jsp:fallback>动作元素篇
- LeetCode 4:Median of Two Sorted Arrays
- Qt 头文件、CONFIG