周赛--Heros and Swords
2015-08-03 07:56
441 查看
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
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 <string.h> #include <math.h> #include <queue> #include <algorithm> #include <stdlib.h> #include <map> #include <set> #include <stdio.h> #include <time.h> using namespace std; #define LL long long #define pi acos(-1.0) #pragma comment(linker, "/STACK:1024000000") const int mod=1e9+7; const int INF=0x3f3f3f3f; const double eqs=1e-9; const int MAXN=1e5+10; int a[MAXN], b[MAXN]; int main() { int t, n, i, j, num=0; LL ans; scanf("%d",&t); while(t--){ scanf("%d",&n); for(i=0;i<n;i++){ scanf("%d",&a[i]); } for(i=0;i<n;i++){ scanf("%d",&b[i]); } sort(a,a+n); sort(b,b+n); ans=1; j=0; for(i=0;i<n;i++) { while(j<n&&a[j]<=b[i]) { j++; } ans=ans*(j-i)%mod; } printf("Case #%d: %lld\n",++num,ans); } return 0; }
相关文章推荐
- 解析大型.NET ERP系统 通用附件管理功能
- 无法访问windows installer服务怎么办
- 机房收费系统之总结篇
- MySQL开发技巧——如何正确使用Join语句
- 架构师速成6.12-开发框架-前端封装
- 《C++ Primier Plus》01
- iOS笔记060 - 自定义控件
- python爬虫(四)--python正则表达式
- CodeForces 219D-Choosing Capital for Treeland(树形dp)
- RocketMQ 刷盘实现
- sql 取一张表的全部外键
- centos 安装git 问题解决方案
- Java学习——Servlet是什么
- HackerRank - "Snakes and Ladders: The Quickest Way Up"
- citrix API 调用案例
- Box Plot
- POJ 3414(BFS建树)
- oc笔记
- 数据库的三范式是什么?
- 计算机的储存架构