HDU 5101 Select (二分)
来源:互联网 发布:java divide 参数 编辑:程序博客网 时间:2024/05/16 15:29
Select
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1572 Accepted Submission(s): 439
Problem Description
One day, Dudu, the most clever boy, heard of ACM/ICPC, which is a very interesting game. He wants to take part in the game. But as we all know, you can't get good result without teammates.
So, he needs to select two classmates as his teammates.
In this game, the IQ is very important, if you have low IQ you will WanTuo. Dudu's IQ is a given number k. We use an integer v[i] to represent the IQ of the ith classmate.
The sum of new two teammates' IQ must more than Dudu's IQ.
For some reason, Dudu don't want the two teammates comes from the same class.
Now, give you the status of classes, can you tell Dudu how many ways there are.
So, he needs to select two classmates as his teammates.
In this game, the IQ is very important, if you have low IQ you will WanTuo. Dudu's IQ is a given number k. We use an integer v[i] to represent the IQ of the ith classmate.
The sum of new two teammates' IQ must more than Dudu's IQ.
For some reason, Dudu don't want the two teammates comes from the same class.
Now, give you the status of classes, can you tell Dudu how many ways there are.
Input
There is a number T shows there are T test cases below. (T≤20 )
For each test case , the first line contains two integers, n and k, which means the number of class and the IQ of Dudu. n (0≤n≤1000 ), k( 0≤k<231 ).
Then, there are n classes below, for each class, the first line contains an integer m, which means the number of the classmates in this class, and for next m lines, each line contains an integer v[i], which means there is a person whose iq is v[i] in this class. m(0≤m≤100 ), v[i]( 0≤v[i]<231 )
For each test case , the first line contains two integers, n and k, which means the number of class and the IQ of Dudu. n (
Then, there are n classes below, for each class, the first line contains an integer m, which means the number of the classmates in this class, and for next m lines, each line contains an integer v[i], which means there is a person whose iq is v[i] in this class. m(
Output
For each test case, output a single integer.
Sample Input
13 11 21 22 1 1
Sample Output
5
Source
BestCoder Round #17
Recommend
heyang | We have carefully selected several similar problems for you: 5717 5716 5715 5714 5713
题意:给定一些集合,选择两个来自不同集合的数,加和大于k,问有多少种选择方案。
思路:ans=从所有数中选择的两个加和大于k的数的方案数-在同一个集合中选择的两个加和大于k的数的方案数
对所有数据排序后二分找即可
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;struct node{__int64 x,id;}b[110000];__int64 cnt,a[1100][1100],c[11000];bool cmp(node a,node b){return a.x<b.x; }__int64 find_a(__int64 x){__int64 l,r,mid;l=0;r=cnt-1;while(l<=r){mid=(l+r)/2;if(b[mid].x<x)l=mid+1;elser=mid-1;}return cnt-l;}__int64 find_b(__int64 x,__int64 id){__int64 l,r,mid;l=0;r=c[id]-1;while(l<=r){mid=(l+r)/2;if(a[id][mid]<x)l=mid+1;elser=mid-1;}return c[id]-l;}int main(){__int64 t,n,m,k,x,i,j,l,ans,sum;scanf("%I64d",&t);while(t--){scanf("%I64d%I64d",&n,&k);cnt=0;for(i=1;i<=n;i++){scanf("%I64d",&m);c[i]=m;for(j=0;j<m;j++){scanf("%I64d",&a[i][j]);b[cnt].x=a[i][j];b[cnt++].id=i;}sort(a[i],a[i]+m);}sort(b,b+cnt,cmp);ans=0;for(i=0;i<cnt;i++){x=k-b[i].x+1;sum=find_a(x);sum-=find_b(x,b[i].id); ans+=sum;}printf("%I64d\n",ans/2);}return 0;}
0 0
- HDU 5101 Select (二分)
- HDU 5101 Select (二分)
- HDU 5101 Select(二分)
- HDU 5101 Select(二分)
- HDU 5101 Select 二分
- HDU 5101 - Select(基本计数 + 二分)
- hdu 5101 Select(思路,容器,二分)
- HDU 5101Select(暴力二分)
- hdu 5101 Select【二分查找】
- 【HDU】 5101 Select 二分搜索 upper_bound
- 【hdu 5101】Select 【二分 +容斥思想】
- hdu 5101(二分)
- HDU5101 Select(二分)
- hdoj 5101 Select 【二分 + 思维】
- 【杭电oj】5101 - Select(STL & 二分)
- hdu 5101 Select
- hdu 5101 select
- HDU 5101 Select
- iOS经典面试题
- BZOJ 2342 双倍回文
- 软件工程(二十七)
- <meta>标签
- JAVA 反射
- HDU 5101 Select (二分)
- 自适应demo
- 意念力治病 人类意念力应用篇之一
- 弹出层-防抖动(示例代码)
- centos screen 命令使用处理SSH连接中断问题
- Android中网络通信的几种方式
- 从此走上一条iOS程序猿不归路。。。
- 产生随机数的两种方法
- JetBrains注册码计算(IntelliJ IDEA 15.0注册码激活)