1371 - Energetic Pandas
2016-05-01 14:58
429 查看
1371 - Energetic Pandas
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.
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].
Problem Setter: F.A. Rezaur Rahman Chowdhury
Special Thanks: Jane Alam Jan
思路:离散化+排列;
PDF (English) | Statistics | Forum |
Time Limit: 2 second(s) | Memory Limit: 32 MB |
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 |
Special Thanks: Jane Alam Jan
思路:离散化+排列;
#include<stdio.h> #include<algorithm> #include<iostream> #include<string.h> #include<queue> #include<stack> using namespace std; typedef long long LL; int ans[10000]; int bns[10000]; int dns[10000]; int cn[10000]; int aa[10000]; int bb[10000]; const int N=1e9+7; int main(void) { int k,i,j; scanf("%d",&k); int ca; int n; for(ca=1; ca<=k; ca++) { scanf("%d",&n); int cnt=0; memset(cn,0,sizeof(cn)); for(i=0; i<n; i++) { scanf("%d",&ans[i]); dns[cnt++]=ans[i]; } for(i=0; i<n; i++) { scanf("%d",&bns[i]); dns[cnt++]=bns[i]; } sort(dns,dns+2*n); for(i=0; i<n; i++) { int l=0; int r=2*n-1; int id=0; while(l<=r) { int mid=(l+r)/2; if(dns[mid]>=ans[i]) { id=mid; r=mid-1; } else l=mid+1; } ans[i]=id; } sort(ans,ans+n); for(i=0; i<n; i++) { int l=0; int r=2*n-1; int id=0; while(l<=r) { int mid=(l+r)/2; if(bns[i]<=dns[mid]) { id=mid; r=mid-1; } else l=mid+1; } bns[i]=id; cn[id]++; } int gg=0; for(i=0; i<3000; i++) { if(cn[i]>0) { aa[gg]=i; bb[gg++]=cn[i]; } } LL sum=1; int cc=gg-1; LL pp=0; for(i=n-1; i>=0; i--) { while(aa[cc]>=ans[i]&&cc>=0) { pp=(pp+bb[cc]); cc --; } if(pp>0) { sum=(sum*pp)%N; pp-=1; } else { sum=0; break; } }printf("Case %d: ",ca); printf("%lld\n",sum); } return 0; }
相关文章推荐
- NSUrSession和AFN
- PC SDK PDFs
- Poj 1428 Children's Dining【哈密顿路径】
- [从头学声学] 第201节 乐器的频率
- Android 在开发中使用单元测试
- 科学开缸、轻松养鱼
- handler和asyncTask比较
- 养鱼“好水”的定义
- 为ListView添加Ripple效果
- OpenCV使用迭代器对像素进行快速操作
- linux下安装安装pcre-8.32 configure: error: You need a C++ compiler for C++ support
- ASP.NET 状态管理(cookie、Session)
- Makefile 自动产生依赖
- PHP (sendmail / PHPMailer / ezcMailComposer)发送邮件
- GEEK编程练习— —连续出现最多子串
- ASP.NET 状态管理(Application)
- 走出消毒的误区
- 退卡操作之触发器的使用
- (Caffe)卷积的实现
- sort---qsort