B - 皇马
2015-08-02 09:56
239 查看
ABCDEFGHIJ
B - 皇马
Time Limit:3000MS Memory Limit:64000KB 64bit IO Format:%lld & %llu
SubmitStatusPracticeACdream
1199
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.
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
对剑的重量和人物的pow都从小到大排序;后面人物可以买前面人物的剑;也就是(j-i)把剑;
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<cstdio> #include<cstring> #include<queue> #include<algorithm> #include<cmath> #include<cstdlib> #include<stack> using namespace std; int sword[100010]; int hero[100010]; int num[100010]; const int MOD=1000000007; int main() { int n,t; while(~scanf("%d",&t)) { int k=0; while(t--) { scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&sword[i]); } for(int j=0;j<n;j++) { scanf("%d",&hero[j]); } sort(sword,sword+n); sort(hero,hero+n); long long ans=1; for(int i=0,j=0;i<n;i++) { while(j<n&&hero[i]>=sword[j]) j++; ans=(ans*(j-i))%MOD; } printf("Case #%d: %lld\n",++k,ans); } } return 0; }
FAQ | About Virtual Judge |
Forum |
Discuss |
Open Source Project
All Copyright Reserved ©2010-2014
HUST ACM/ICPC TEAM
Anything about the OJ, please ask in the
forum, or contact author:Isun
Server Time: 2015-08-02 09:52:44
相关文章推荐
- LOG4J
- jquery里的dialog对话框插件为框架页(iframe) 的方法
- 【Cocos2d入门教程十二】浅析Cocos2d下的粒子系统
- 前端工程师知识体系
- 黑马程序员——多线程
- 【leetCode】Valid Anagram
- ABP分层架构
- Protect JavaScript source code with v8 snapshot
- Hibernate学习(3)框架简述
- Ubuntu下中文完美解决方案
- 第13章 使用打印机_13.2 打印图形和文字
- linux虚拟机下Hadoop集群分布式配置
- [深入理解Android卷一全文-第三章]深入理解init
- acdream1084(数论入门)
- 酷我音乐歌手写真接口分享
- Decode Ways
- 常见UML和建模工具比较
- 使用pip升级所有package笔记
- [LeetCode]231.Power of Two
- 强迫症治疗的两个陷阱