1371 - Energetic Pandas
Time Limit: 2 second(s) Memory Limit: 32 MB

There are n bamboos of different weights Wi. There are n pandas of different capacity CAPi. How many ways the pandas can carry the bamboos so that each panda carries exactly one bamboo, every bamboo is carried by one panda and a panda cannot carry a bamboo that is heavier than its capacity. Two ways will be considered different if at least one panda carries a different bamboo.

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with a line containing an integer n (1 ≤ n ≤ 1000) denoting the number of pandas and bamboos. The next line contains n space separated distinct integers denoting the weights of be bamboos. The next line contains n space separated distinct integers denoting the capacities for the pandas. The weights and the capacities lie in the range [1, 109].

Output

For each case, print the case number and the number of ways those pandas can carry the bamboos. This number can be very big. So print the result modulo 1000 000 007.

Sample Input

Output for 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

Case 1: 1

Case 2: 0

Case 3: 4


Problem Setter: F.A. Rezaur Rahman Chowdhury
Special Thanks: Jane Alam Jan
思路:离散化+排列;
  1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<string.h>
5 #include<queue>
6 #include<stack>
7 using namespace std;
8 typedef long long LL;
9 int ans[10000];
10 int bns[10000];
11 int dns[10000];
12 int cn[10000];
13 int aa[10000];
14 int bb[10000];
15 const int N=1e9+7;
16 int main(void)
17 {
18 int k,i,j;
19 scanf("%d",&k);
20 int ca;
21 int n;
22 for(ca=1; ca<=k; ca++)
23 {
24 scanf("%d",&n);
25 int cnt=0;
26 memset(cn,0,sizeof(cn));
27 for(i=0; i<n; i++)
28 {
29 scanf("%d",&ans[i]);
30 dns[cnt++]=ans[i];
31 }
32 for(i=0; i<n; i++)
33 {
34 scanf("%d",&bns[i]);
35 dns[cnt++]=bns[i];
36 }
37 sort(dns,dns+2*n);
38 for(i=0; i<n; i++)
39 {
40 int l=0;
41 int r=2*n-1;
42 int id=0;
43 while(l<=r)
44 {
45 int mid=(l+r)/2;
46 if(dns[mid]>=ans[i])
47 {
48 id=mid;
49 r=mid-1;
50 }
51 else l=mid+1;
52 }
53 ans[i]=id;
54 }
55 sort(ans,ans+n);
56 for(i=0; i<n; i++)
57 {
58 int l=0;
59 int r=2*n-1;
60 int id=0;
61 while(l<=r)
62 {
63 int mid=(l+r)/2;
64 if(bns[i]<=dns[mid])
65 {
66 id=mid;
67 r=mid-1;
68 }
69 else l=mid+1;
70 }
71 bns[i]=id;
72 cn[id]++;
73 }
74 int gg=0;
75 for(i=0; i<3000; i++)
76 {
77 if(cn[i]>0)
78 {
79 aa[gg]=i;
80 bb[gg++]=cn[i];
81 }
82 }
83 LL sum=1;
84 int cc=gg-1;
85 LL pp=0;
86 for(i=n-1; i>=0; i--)
87 {
88
89 while(aa[cc]>=ans[i]&&cc>=0)
90 {
91 pp=(pp+bb[cc]);
92 cc --;
93 }
94 if(pp>0)
95 {
96 sum=(sum*pp)%N;
97 pp-=1;
98 }
99 else
100 {
101 sum=0;
102 break;
103 }
104 }printf("Case %d: ",ca);
105 printf("%lld\n",sum);
106 }
107 return 0;
108 }

1371 - Energetic Pandas的更多相关文章

  1. \(\rm LightOJ 1371 - Energetic Pandas 简单计数+组合\)

    http://www.lightoj.com/volume_showproblem.php?problem=1371 题意:给你n根竹子,和n只熊猫(XD),每个熊猫只能选择重量不大于它的竹子,问有几 ...

  2. BNU 13289 Energetic Pandas DP

     Energetic Pandas  There are n bamboos of different weights Wi. There are n pandas of different capa ...

  3. 五、Pandas玩转数据

    Series的简单运算 import numpy as np import pandas as pd s1=pd.Series([1,2,3],index=['A','B','C']) print(s ...

  4. pandas基础-Python3

    未完 for examples: example 1: # Code based on Python 3.x # _*_ coding: utf-8 _*_ # __Author: "LEM ...

  5. 10 Minutes to pandas

    摘要   一.创建对象 二.查看数据 三.选择和设置 四.缺失值处理 五.相关操作 六.聚合 七.重排(Reshaping) 八.时间序列 九.Categorical类型   十.画图      十一 ...

  6. 利用Python进行数据分析(15) pandas基础: 字符串操作

      字符串对象方法 split()方法拆分字符串: strip()方法去掉空白符和换行符: split()结合strip()使用: "+"符号可以将多个字符串连接起来: join( ...

  7. 利用Python进行数据分析(10) pandas基础: 处理缺失数据

      数据不完整在数据分析的过程中很常见. pandas使用浮点值NaN表示浮点和非浮点数组里的缺失数据. pandas使用isnull()和notnull()函数来判断缺失情况. 对于缺失数据一般处理 ...

  8. 利用Python进行数据分析(12) pandas基础: 数据合并

    pandas 提供了三种主要方法可以对数据进行合并: pandas.merge()方法:数据库风格的合并: pandas.concat()方法:轴向连接,即沿着一条轴将多个对象堆叠到一起: 实例方法c ...

  9. 利用Python进行数据分析(9) pandas基础: 汇总统计和计算

    pandas 对象拥有一些常用的数学和统计方法.   例如,sum() 方法,进行列小计:   sum() 方法传入 axis=1 指定为横向汇总,即行小计:   idxmax() 获取最大值对应的索 ...

随机推荐

  1. LeetCode 从头到尾打印链表

    LeetCode 从头到尾打印链表 题目描述 输入一个链表头节点,从尾到头反过来返回每个节点的值(用数组返回). 示例 1: 输入:head = [1,3,2] 输出:[2,3,1] 一得之见(Jav ...

  2. Scala【json字符串和json对象互相转换】

    一.fastjson工具 pom依赖 <dependency> <groupId>com.alibaba</groupId> <artifactId>f ...

  3. 淘宝、网易移动端 px 转换 rem 原理,Vue-cli 实现 px 转换 rem

       在过去的一段时间里面一直在使用Vue配合 lib-flexible和px2rem-loader配合做移动端的网页适配.秉着求知的思想,今天决定对他的原理进行分析.目前网上比较主流使用的就是淘宝方 ...

  4. Vue框架,computed和watch的区别

    computed和watch定义 1.computed是计算属性,类似于过滤器,对绑定到视图的数据进行处理.官网的例子: <div id="example"> < ...

  5. _BSMachError: (os/kern) invalid capability (20) _BSMachError: (os/kern) invalid name (15) 问题的解决

    在项目中突然遇到一个问题,也就是_BSMachError: (os/kern) invalid capability (20) _BSMachError: (os/kern) invalid name ...

  6. nodejs代码初探之nodejs启动

    nodejs启动 入口在node_main.cc,解析参数后进入node.cc 中的node::Start() V8::Initialize() //初始化v8SetupProcessObject() ...

  7. sax方式解析XML学习笔记

    原理:对文档进行顺序扫描,当扫描到文档(document)开始与结束,元素开始与结束.文档结束等地方 通知事件处理函数,由事件处理函数相应动作然后继续同样的扫描,直至文档结束. 优点:消耗资源比较少: ...

  8. 基于jar的Spring Boot工程

    一.Spring Boot简介 Spring Boot是由Pivotal[ˈpɪvətl]团队(一家做大数据的公司)提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架 ...

  9. zookeeper 异常 :stat is not executed because it is not in the whitelist. Connection closed b

    1 .问题 1.启动 zookeeper 后 用指令:  telnet 127.0.0.1 2181 连接 提示输入指令 :stat 后报错,然后关闭连接 2.问题解决: 修改启动指令 zkServe ...

  10. 什么是微服务,SpringBoot和SpringCloud的关系和区别

    什么是微服务? 就目前而言对于微服务业界没有一个统一的,标准的定义.但通常而言,微服务是一种架构模式或者说是一种架构风格,它提倡单一应用程序划分为一组小的服务,每个服务在其独立的自己的进程中,服务之间 ...