HDOJ 5101 Select(upper_bound的运用)
来源:互联网 发布:hebe掰弯selina知乎 编辑:程序博客网 时间:2024/06/05 04:08
Select
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1887 Accepted Submission(s): 539
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. (
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
先贴出lower_bound和upper_bound的用法
(1)lower_bound (a,a+n,t) 返回非递减序列a[0]~a[n-1]第一个大于等于值t的位置
(2)upper_bound(a,a+n,t) 返回非递减序列a[0]~a[n-1]第一个大于值t的位置
注:没找到则返回最后一个位置
例如a[5]={1,3,7,7,9};
lower_bound(a,a+5,7) - a的值为 2
upper_bound(a,a+5,7) - a的值为 4
#include <bits/stdc++.h>using namespace std;#define mst(a,b) memset((a),(b),sizeof(a))#define f(i,a,b) for(int i=(a);i<(b);++i)const int maxn = 1005;const int mod = 1000000007;const int INF = 1e9;#define ll long long#define rush() int T;scanf("%d",&T);while(T--)int a[maxn][105];int b[maxn*100];int num[maxn];int n,k,m;void init(){ mst(a,0); mst(b,0); mst(num,0);}int main(){ rush() { init(); scanf("%d%d",&n,&k); int cnt=0; f(i,0,n) { scanf("%d",&num[i]); f(j,0,num[i]) { scanf("%d",&a[i][j]); b[cnt++]=a[i][j]; } sort(a[i],a[i]+num[i]); } sort(b,b+cnt); ll ans=0; f(i,0,n) { f(j,0,num[i]) { int t=k-a[i][j]; int x1=upper_bound(b,b+cnt,t)-b; //所有人里找IQ>t的 ans+=(cnt-x1); if(t<a[i][num[i]-1]) { int x2=upper_bound(a[i],a[i]+num[i],t)-a[i]; //某个班级里IQ>t的 ans-=(num[i]-x2); } } } printf("%I64d\n",ans/2); (x,y),(y,x)如此重复算了两遍 } return 0;}
- HDOJ 5101 Select(upper_bound的运用)
- hdu 4288(lower_bound&&upper_bound的运用)
- 二分lower_bound()与upper_bound()的运用
- 【HDU】 5101 Select 二分搜索 upper_bound
- hdu 4288 Coder(线段树+离散化,lower_bound&&upper_bound的运用)
- 【BestCoder】 HDOJ 5101 Select
- hdoj 5101 Select
- HDOJ 1247 Hat’s Words(strncpy函数的运用)
- HDOJ 5101 Select 树状数组
- hdoj 5101 Select 【二分 + 思维】
- lower_bound upper_bound的简单实现(STL)
- 左右添加删除SELECT标签的运用
- upper_bound\lower_bound的用法
- lower_bound,upper_bound的用法
- 二分(upper_bound)
- lower_bound/upper_bound(STL)
- upper_bound
- hdoj 3746 Cyclic Nacklace 【kmp(len%(len-p[len])公式的灵活运用)】
- 微信公众平台企业号回调模式的URL验证——Java
- ssh整合出现action注入空指针异常
- Ubuntu16.04 安装xgboost(anaconda3)
- 大小写字母转换
- NUMA架构的CPU – 你真的用好了么?
- HDOJ 5101 Select(upper_bound的运用)
- 闭包的理解
- 论文笔记:Feature Pyramid Networks for Object Detection
- 4-5 求自定类型元素的最大值
- Java NIO通信简单实例
- 什么是I帧,P帧,B帧
- 【C#】CSV文件读写
- java &与&& |与||的区别
- Mybatis的sqlMapConfig.xml中mappers标签