1371 - Energetic Pandas

  PDF (English) Statistics Forum
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 }
时间: 2024-08-10 19:17:20

1371 - Energetic Pandas的相关文章

用pandas分析百万电影数据

用pandas分析电影数据 Lift is short, use Python. 用Python做数据分析,pandas是Python数据分析的重要包,其他重要的包:numpy.matplotlib . 安装pandas(Linux, Mac, Windows皆同): pip install pandas 电影数据来源:http://grouplens.org/datasets/movielens/ 下载数据文件解压,包含如下4个文件: users.dat 用户数据 movies.dat 电影数

一些Pandas常用方法

Series(列)方法describe(),对于不同类型的变量的列,有不同返回值(http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.describe.html) >>> s = pd.Series([1, 2, 3]) >>> s.describe() count 3.0 mean 2.0 std 1.0 min 1.0 25% 1.5 50% 2.0 75% 2.5 max 3

Pandas学习之常用函数详解

本文和大家分享的主要是Pandas库常用函数相关内容,一起来看看吧,希望对大家学习Pandas有所帮助. 1. DataFrame 处理缺失值 pandas.DataFrame.dropna df2.dropna(axis=0, how='any', subset=[u'ToC'], inplace=True) 把在ToC列有缺失值的行去掉 2. 根据某维度计算重复的行 pandas.DataFrame.duplicated print df.duplicated(['name']).value

用scikit-learn和pandas学习线性回归

对于想深入了解线性回归的童鞋,这里给出一个完整的例子,详细学完这个例子,对用scikit-learn来运行线性回归,评估模型不会有什么问题了. 1. 获取数据,定义问题 没有数据,当然没法研究机器学习啦.:) 这里我们用UCI大学公开的机器学习数据来跑线性回归. 数据的介绍在这: http://archive.ics.uci.edu/ml/datasets/Combined+Cycle+Power+Plant 数据的下载地址在这: http://archive.ics.uci.edu/ml/ma

python之pandas模块的基本使用(1)

一.pandas概述 pandas :pannel data analysis(面板数据分析).pandas是基于numpy构建的,为时间序列分析提供了很好的支持.pandas中有两个主要的数据结构,一个是Series,另一个是DataFrame. 二.数据结构 Series Series 类似于一维数组与字典(map)数据结构的结合.它由一组数据和一组与数据相对应的数据标签(索引index)组成.这组数据和索引标签的基础都是一个一维ndarray数组.可将index索引理解为行索引. Seri

Pandas中如何处理大数据?

近期的工作和Hive SQL打交道比较多,偶尔遇到一些SQL不好解决的问题,会将文件下载下来用pandas来处理,由于数据量比较大,因此有一些相关的经验可以和大家分享,希望对大家学习pandas有所帮助吧. 大文本数据的读写 有时候我们会拿到一些很大的文本文件,完整读入内存,读入的过程会很慢,甚至可能无法读入内存,或者可以读入内存,但是没法进行进一步的计算,这个时候如果我们不是要进行很复杂的运算,可以使用read_csv提供的chunksize或者iterator参数,来部分读入文件,处理完之后

十分钟入门pandas数据结构和索引

pandas数据结构和索引是入门pandas必学的内容,这里就详细给大家讲解一下,看完本篇文章,相信你对pandas数据结构和索引会有一个清晰的认识. 一.数据结构介绍 在pandas中有两类非常重要的数据结构,即序列Series和数据框DataFrame.Series类似于numpy中的一维数组,除了通吃一维数组可用的函数或方法,而且其可通过索引标签的方式获取数据,还具有索引的自动对齐功能:DataFrame类似于numpy中的二维数组,同样可以通用numpy数组的函数和方法,而且还具有其他灵

pandas cookbook【1】

网上看到了关于pandas的用法,虽然练习了不少,但是还是有些不是能记得很清楚.所以就写下来了. chapter1讲的是读取CSV文件.如下代码: 1 #%% 2 import pandas as pd 3 import numpy as np 4 import matplotlib.pyplot as plt 5 # make the graphs a bit prettier 6 pd.set_option('display.mpl_style','default') 7 plt.rcPar

《Python数据分析常用手册》一、NumPy和Pandas篇

一.常用链接: 1.Python官网:https://www.python.org/ 2.各种库的whl离线安装包:http://www.lfd.uci.edu/~gohlke/pythonlibs/#scikit-learn 3.数据分析常用库的离线安装包(pip+wheels)(百度云):http://pan.baidu.com/s/1dEMXbfN 密码:bbs2 二.常用库 1.NumPy NumPy是高性能科学计算和数据分析的基础包.部分功能如下: ndarray, 具有矢量算术运算和