博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
周赛-Heros and Swords 分类: 比赛 ...
阅读量:5303 次
发布时间:2019-06-14

本文共 1875 字,大约阅读时间需要 6 分钟。

Heros and Swords

Time Limit: 6000/3000MS (Java/Others) 
Memory Limit: 128000/64000KB (Java/Others)
   

Problem Description

There are n swords of different weights Wi and 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.

Sample Input

351 2 3 4 51 2 3 4 521 32 232 3 46 3 5

Sample Output

Case #1: 1Case #2: 0Case #3: 4
一道贪心的题,在贪心中处理组合数用的2*n的时间复杂度,精妙
 
#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define LL long long#define RR freopen("output.txt","r",stdoin)#define WW freopen("input.txt","w",stdout)using namespace std;const int MAX = 100100;const int MOD = 1000000007;int n;int w[MAX],p[MAX];int num[MAX];int main(){ int T; int W=1; scanf("%d",&T); while(T--) { scanf("%d",&n); for(int i=0;i
for(int i=0,j=0;i

版权声明:本文为博主原创文章,未经博主允许不得转载。

转载于:https://www.cnblogs.com/juechen/p/4721946.html

你可能感兴趣的文章
Java抽象类和接口的比较
查看>>
开发进度一
查看>>
MyBaits学习
查看>>
管道,数据共享,进程池
查看>>
CSS
查看>>
[LeetCode] 55. Jump Game_ Medium tag: Dynamic Programming
查看>>
[Cypress] Stub a Post Request for Successful Form Submission with Cypress
查看>>
程序集的混淆及签名
查看>>
判断9X9数组是否是数独的java代码
查看>>
00-自测1. 打印沙漏
查看>>
UNITY在VS中调试
查看>>
SDUTOJ3754_黑白棋(纯模拟)
查看>>
Scala入门(1)Linux下Scala(2.12.1)安装
查看>>
如何改善下面的代码 领导说了很耗资源
查看>>
Quartus II 中常见Warning 原因及解决方法
查看>>
php中的isset和empty的用法区别
查看>>
Android ViewPager 动画效果
查看>>
pip和easy_install使用方式
查看>>
博弈论
查看>>
Redis sentinel & cluster 原理分析
查看>>