Select

                                                   Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

                                                                   Total Submission(s): 285    Accepted Submission(s): 85

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.
 
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 )
 
Output
For each test case, output a single integer.
 
Sample Input
1
3 1
1 2
1 2
2 1 1
 
Sample Output
5
 

    一个人要选两名队员,两名队员的IQ之和要大于他的,另两名队员不能在一个班级。


   这题的二分思路还是非常easy想出来的,总人数1000*100,时限为2s,复杂度肯定为nlog(n),又由于是找比一个数大的。非常符合二分的性质。



     官方题解:

  答案=从全部数中选择的两个加和大于k的数的方案数-在同一个集合中选择的两个加和大于k的数的方案数
而对于同一个集合中选择的两个加和大于k的方案数是能够直接排序然后利用单调性高速统计出来的。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn=100000+100;
int a[maxn];
int map[1010][110];
int v[1010];
int cur;
int finda(int x)//在大的区间二分查找
{
int l=0;
int r=cur-1;
if(x>=a[r])
return cur;
while(l<r)
{
int m=(l+r)>>1;
if(a[m]<=x)
l=m+1;
else
r=m;
}
return l;
}
int find(int p,int x)//在小区间二分查找
{
if(x>=map[p][v[p]-1])
return v[p];
int l=0;
int r=v[p]-1;
while(l<r)
{
int m=(l+r)>>1;
if(map[p][m]>x)
r=m;
else
l=m+1;
}
return l;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,k,m;
scanf("%d%d",&n,&k);
cur=0;
for(int i=0;i<n;i++)
{
scanf("%d",&v[i]);
m=v[i];
for(int j=0;j<m;j++)
{
scanf("%d",&map[i][j]);
a[cur++]=map[i][j];
}
sort(map[i],map[i]+m);
}
sort(a,a+cur);
long long ans=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<v[i];j++)
{
int to=k-map[i][j];
int temp=cur-finda(to);
int temp2=v[i]-find(i,to);
ans+=(temp-temp2);
}
}
printf("%I64d\n",ans/2);
}
return 0;
}

hdu 5101 Select(Bestcoder Round #17)的更多相关文章

  1. hdu 5636 搜索 BestCoder Round #74 (div.2)

    Shortest Path  Accepts: 40  Submissions: 610  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: ...

  2. hdu 5101 Select

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5101 Select Description One day, Dudu, the most cleve ...

  3. HDU 5904 - LCIS (BestCoder Round #87)

    HDU 5904 - LCIS [ DP ]    BestCoder Round #87 题意: 给定两个序列,求它们的最长公共递增子序列的长度, 并且这个子序列的值是连续的 分析: 状态转移方程式 ...

  4. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  5. HDU 5101 Select --离散化+树状数组

    题意:n 组,每组有一些值,求 在不同的两组中每组选一个使值的和大于k的方法数. 解法:n * Cnt[n] <= 1000*100 = 100000, 即最多10^5个人,所以枚举每个值x,求 ...

  6. HDU 5778 abs (BestCoder Round #85 C)素数筛+暴力

    分析:y是一个无平方因子数的平方,所以可以从sqrt(x)向上向下枚举找到第一个无平方因子比较大小 大家可能觉得这样找过去暴力,但实际上无平方因子的分布式非常密集的,相关题目,可以参考 CDOJ:无平 ...

  7. HDU 5776 sum (BestCoder Round #85 A) 简单前缀判断+水题

    分析:就是判断简单的前缀有没有相同,注意下自身是m的倍数,以及vis[0]=true; #include <cstdio> #include <cstdlib> #includ ...

  8. hdu 5101 Select (二分+单调)

    题意: 多多有一个智商值K. 有n个班级,第i个班级有mi个人.智商分别是v1,v2,.....vm. 多多要从这些人中选出两人.要求两人智商和大于K,并且两人不同班.问总共有多少种方案. 数据范围: ...

  9. hdu 5101(思路题)

    Select Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

随机推荐

  1. jenkins 通过批处理自动构建 非标准项目

    之前介绍了java和vs2010的项目构建,这些都是比较常见的,所以都用专门的工具.但但难免会遇到一些不常见的项目,下面介绍通过批处理进行构建,并用jenkins调用.我们这里使用plc语言,没有标准 ...

  2. 优酷m3u8视频源地址获取失败

    昨天和今天上午,优酷站点视频全然没有办法播放,可是我是获取的优酷视频的视频原地址,所以app还是能够正常播放而且有下载功能.今天下午開始,优酷视频网页能够訪问了,可是视频原地址却不在了.我全部的app ...

  3. Android中使用JNI获得APK签名的哈希值

    原地址:http://blog.csdn.net/i5suoi/article/details/19036975 最近在研究android应用中的安全问题,貌似只有将核心代码写到JNI底层才是最安全的 ...

  4. Fast portable non-blocking network programming with Libevent

    Fast portable non-blocking network programming with Libevent Fast portable non-blocking network prog ...

  5. 启动和关闭JBoss As 7.1.1脚本

    启动和关闭JBoss As 7.1.1,脚本例如以下djboss.sh: #!/bin/sh #JBOSS_HOME JBOSS_HOME=/opt/jboss case "$1" ...

  6. 敏捷开发-Scrum 真实

    近期研究前 Scrum 数据编译的文件,在接下来的团队和项目开发.项目根据该引入 Scrum 一些练习,提高团队成员和项目之间的交付质量的合作. 参考资料: <轻松Scrum之旅-敏捷开发故事& ...

  7. Android基于发展Service音乐播放器

    这是一个基于Service组件的音乐播放器,程序的音乐将会由后台的Service组件负责播放,当后台的播放状态改变时,程序将会通过发送广播通知前台Activity更新界面:当用户单击前台Activit ...

  8. poj1182(并查集)

    题目链接 分析:根据分析,关系的递推满足由[a,b]~[b,c]得:[a,c]=([a,b]+[b,c])%3;[a,d]=([a,b]+[b,c]+[c,d])%3.由rank数组表示关系 0 -  ...

  9. 32位Linux文件限制大小

    线上程序不断重新启动,查看log发现是进程由于SIGXFSZ信号退出.对过大的文件进行操作的时候会产生此信号,一般仅仅在32位机器上出现,文件限制大小为2G.用lsof查看进程打开的文件,果然有一个文 ...

  10. Django URL 命名空间

    https://docs.djangoproject.com/en/1.5/topics/http/urls/#introduction 译文: URL 命名空间 简介: 当你需要部署一个应用的多个实 ...