hdu 5101 Select
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=5101
Select
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 \leq 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 \leq n \leq 1000), k\ ( 0 \leq k \leq 2^{31} ).$
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 \leq m \leq 100 ), v[i]\ ( 0 \leq v[i] < 2^{31} )$
Output
For each test case, output a single integer.
Sample Input
1
3 1
1 2
1 2
2 1 1
Sample Output
5
思路:从所有数中选择的两个加和大于k的数的方案数-在同一个集合中选择的两个加和大于k的数的方案数。。。
先排序,再二分。。
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
using std::cin;
using std::cout;
using std::endl;
using std::find;
using std::sort;
using std::set;
using std::map;
using std::pair;
using std::vector;
using std::lower_bound;
#define pb(e) push_back(e)
#define sz(c) (int)(c).size()
#define mp(a, b) make_pair(a, b)
#define all(c) (c).begin(), (c).end()
#define iter(c) decltype((c).begin())
#define cls(arr,val) memset(arr,val,sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
const int N = ;
typedef long long ll;
int num[N], arr[N * ], rec[N][];
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
ll ans;
int t, n, k, tot;
scanf("%d", &t);
while (t--) {
ans = tot = ;
scanf("%d %d", &n, &k);
rep(i, n) {
scanf("%d", &num[i]);
rep(j, num[i]) scanf("%d", &rec[i][j]), arr[tot++] = rec[i][j];
}
sort(arr, arr + tot);
rep(i, tot) ans += tot - (lower_bound(arr + i, arr + tot, k - arr[i] + ) - arr);
rep(i, n) {
sort(rec[i], rec[i] + num[i]);
rep(j, num[i]) {
ans -= num[i] - (lower_bound(rec[i] + j, rec[i] + num[i], k - rec[i][j] + ) - rec[i]);
}
}
printf("%lld\n", ans);
}
return ;
}
hdu 5101 Select的更多相关文章
- hdu 5101 Select(Bestcoder Round #17)
Select Time Limit: 4000/2000 MS (Java/Others) ...
- HDU 5101 Select --离散化+树状数组
题意:n 组,每组有一些值,求 在不同的两组中每组选一个使值的和大于k的方法数. 解法:n * Cnt[n] <= 1000*100 = 100000, 即最多10^5个人,所以枚举每个值x,求 ...
- hdu 5101 Select (二分+单调)
题意: 多多有一个智商值K. 有n个班级,第i个班级有mi个人.智商分别是v1,v2,.....vm. 多多要从这些人中选出两人.要求两人智商和大于K,并且两人不同班.问总共有多少种方案. 数据范围: ...
- BestCoder17 1002.Select(hdu 5101) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5101 题目意思:给出 n 个 classes 和 Dudu 的 IQ(为k),每个classes 都有 ...
- hdu 5101 n集合选2个不同集合数使和大于k
http://acm.hdu.edu.cn/showproblem.php?pid=5101 给n个集合,选择两个来自不同集合的数,加和大于k,问有多少种选择方案. 答案=从所有数中选择的两个加和大于 ...
- hdu 5101(思路题)
Select Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- HDU 5101
hdoj5101 lower_bound函数: 题意: 从两个不同集合拿出两个数,加的和大于k的可行的方案数 思路: 答案=从所有数中选择的两个加和大于k的数的方案数-在同一个集合中选择的两个加和大于 ...
- 牛客练习赛16 F 选值【二分/计数】
链接:https://www.nowcoder.com/acm/contest/84/F 来源:牛客网 题目描述 给定n个数,从中选出三个数,使得最大的那个减最小的那个的值小于等于d,问有多少种选法. ...
- Cnblog页面美化小记
Cnblog页面美化小记 这两天我在网上翻找了许许多多的资料,打开了不计其数的博客,对着\(js\).\(html\).\(css\)等文件删删改改,在浏览器和\(vscode\)间辗转腾挪...总算 ...
随机推荐
- SDUT 3347 数据结构实验之数组三:快速转置
数据结构实验之数组三:快速转置 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 转置运算是一 ...
- Exercises - Kangaroo
Write a definition for a class named Kangaroo with the following methods: An __init__ method that in ...
- 学习总结 JAVA环境配置 及其相应的步骤
相应的操作步骤 第一步: 右键我的电脑→属性→高级系统设置→环境变量→打开环境变量 第二步:在系统变量中添加JAVA_HOME ,并引用到相对应的地址. 第三步:在系统变量 path 中最前端(按ho ...
- 华为OJ平台——将真分数分解为埃及分数
题目描述: 分子为1的分数称为埃及分数.现输入一个真分数(分子比分母小的分数,叫做真分数),请将该分数分解为埃及分数.如:8/11 = 1/2+1/5+1/55+1/110. 输入: 输入一个真分数, ...
- com组件 Ieframe的主页锁定
CLSID 里的ieframe的 shell OpenHomePage-> Command的默认项"C:\Program Files (x86)\Internet Explorer\i ...
- 【Spring 2】spring的属性注入形式
一.注入简介 spring是一个java bean的容器,它摒弃了过去通过new关键字调用类再调用类的实例的形式,通过依赖注入维护者一系列的java bean的示例.通过spring所提供的依赖注入 ...
- golang初体验
使用golang开发已经有一个多月了,除了一开始遇到的各种小白问题,IDE的选择,gopath,goroot的配置...后边还算顺风顺水的.实践体验,golang真的适合快速开发.特别是后台开发,直接 ...
- oracle 游标示例
declare iCount int:=0; sPath nvarchar2(200); tdzsh nvarchar2(50);begin for x in (select c.imgpath fr ...
- ASP.NET的SEO:基础知识
本系列目录 首先谈一点我自己的体会,我还是希望能和大家分享: 当你读到一定数量的SEO资料后,你会发现,对同一个问题,众说纷纭,莫衷一是.这其实主要是因为以下一些原因造成的:1. 很多SEO技巧,是& ...
- rsync 安装与配置
1.什么是rsync Rsync(remote synchronize)是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件.Rsync使用所谓的“Rsync算法”来使本地和远 程两个 ...