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. RCP开发中错误:java.lang.RuntimeException: WARNING: Prevented recursive attempt to activate part...

    在做RCP的eclipse插件开发时,启动管理软件界面时,总是报如下错误 : !ENTRY org.eclipse.ui.workbench 4 0 2012-05-25 18:44:21.306 ! ...

  2. fs学习笔记之输出格式

    接触fs那么久,有必要再记录一下. 上一篇介绍了fs拓扑描写叙述文件dot的格式,今天要介绍fs输出文件的格式. 举个样例,下面是d节点输出文件的一行记录,也就是一条流经过d的记录. textexpo ...

  3. atitit.高级编程语言的特性 and 未来趋势与进化.doc

    atitit.高级编程语言的特性 and 未来趋势与进化.doc 1 编程语言的发展历程 1 1.1 编程语言的进化,起始发现背后的思想 :不论什么两个系统之间的复杂性,都能够通过加入一个抽象层要屏蔽 ...

  4. poj1182(并查集)

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

  5. HTC one/M7电信802d 毒蛇ViperOne2.1.0/高级毒蛇工具/完美root,精简/更多自定义,稳定,流畅ROM

    ROM版本 HTC One/M7 802d ROM作者 雪狼团队·大盛 http://weibo.com/DaShengdd Android版本 Android 4.2.2 创建日期 2013.09. ...

  6. 什么是gulp?

    gulp初涉 1.什么是gulp? gulp是前端开发过程中一种基于流的代码构建工具,是自动化项目的构建利器:它不仅能对网站资源进行优化,而且在开发过程中很多重复的任务能够使用正确的工具自动完成:使用 ...

  7. C#之异步编程

    1 异步编程的重要性 C#5.0最重要的改进是提供了更强大的异步编程,C#5.0仅增加两个关键字Async和Await,使用异步编程,方法调用是后台运行(通常在线程和任务的帮助下),并且不会阻塞调用线 ...

  8. wampserver图标黄色

    wampserver图标黄色(多个httpd.exe服务,以前装了apache) 服务--->httpd.exe右击这个服务打开文件位置就知道是不是wampserver的服务.如果不是就停掉这给 ...

  9. xamarin跨平台iOS、Android 与Windows

    http://xamarin.csdn.net/ Xamarin是一个行动App开发平台,提供跨平台开发能力,开发人员透过Xamarin开发工具与程序语言,即可开发出iOS.Android 与Wind ...

  10. js中 正則表達式

    正則表達式使用具体解释 简单介绍 简单的说,正則表達式是一种能够用于模式匹配和替换的强有力的工具.其作用例如以下: 測试字符串的某个模式.比如,能够对一个输入字符串进行測试,看在该字符串是否存在一个电 ...