HDU 5101
hdoj5101 lower_bound函数;
题意:
从两个不同集合拿出两个数,加的和大于k的可行的方案数
思路: 答案=从所有数中选择的两个加和大于k的数的方案数-在同一个集合中选择的两个加和大于k的数的方案数
对于同一个集合中选择的两个加和大于k的方案数,
直接排序,
然后利用单调性快速统计出来的。
————————————————————————。
#include<iostream>
#include<cstdio>
#include<stdlib.h>
#include<vector>
#include<string.h>
#include<algorithm>
using namespace std;
typedef long long LL;
#define INF 0x3f3f3f3f
int main()
{
int T,x;
int n,k,m;
scanf("%d",&T);
while(T--)
{
vector<int>q[1010];
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)
{
scanf("%d",&m);
for(int j=1;j<=m;j++)
{
scanf("%d",&x);
q[i].push_back(x);
q[0].push_back(x);
}
sort(q[i].begin(),q[i].end());
}
sort(q[0].begin(),q[0].end());
LL ans=0;
LL num1,num2;
int v;
for(int i=1;i<=n;i++)
{
for(int j=0;j<(int)q[i].size();j++)
{
v=q[i][j];
num1=q[0].end()-lower_bound(q[0].begin(),q[0].end(),k-v+1); //最低插入地址;
num2=q[i].end()-lower_bound(q[i].begin(),q[i].end(),k-v+1);
ans+=num1-num2;
}
}
printf("%lld\n",ans/2);
}
return 0;
}
HDU 5101的更多相关文章
- hdu 5101 n集合选2个不同集合数使和大于k
http://acm.hdu.edu.cn/showproblem.php?pid=5101 给n个集合,选择两个来自不同集合的数,加和大于k,问有多少种选择方案. 答案=从所有数中选择的两个加和大于 ...
- BestCoder17 1002.Select(hdu 5101) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5101 题目意思:给出 n 个 classes 和 Dudu 的 IQ(为k),每个classes 都有 ...
- hdu 5101 Select
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5101 Select Description One day, Dudu, the most cleve ...
- HDU 5101 Select --离散化+树状数组
题意:n 组,每组有一些值,求 在不同的两组中每组选一个使值的和大于k的方法数. 解法:n * Cnt[n] <= 1000*100 = 100000, 即最多10^5个人,所以枚举每个值x,求 ...
- hdu 5101 Select(Bestcoder Round #17)
Select Time Limit: 4000/2000 MS (Java/Others) ...
- hdu 5101(思路题)
Select Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- hdu 5101 Select (二分+单调)
题意: 多多有一个智商值K. 有n个班级,第i个班级有mi个人.智商分别是v1,v2,.....vm. 多多要从这些人中选出两人.要求两人智商和大于K,并且两人不同班.问总共有多少种方案. 数据范围: ...
- 牛客练习赛16 F 选值【二分/计数】
链接:https://www.nowcoder.com/acm/contest/84/F 来源:牛客网 题目描述 给定n个数,从中选出三个数,使得最大的那个减最小的那个的值小于等于d,问有多少种选法. ...
- HDU 4417 Super Mario(主席树求区间内的区间查询+离散化)
Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
随机推荐
- POJ训练计划1035_Spell checker(串处理/暴力)
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 18418 Accepted: 6759 De ...
- saltstack安装配置(syndic)
syndic是saltstack用来做集群部署的,一般结构如图: syndic是一个特殊的minion,syndic类继承于minion类,syndic可以看作一个代理,只做数据传递. CentOS上 ...
- 常用DOS下MSC指令
xp:copy C:\WINDOWS\repair\*.* 到 c:\windows\system32\config 2k: copy C:\winnt\repair\*.* 到 c:\winnt\s ...
- alsa声卡切换
环境 ubuntu12.04 因为桌面版的默认装了,而且调声音也很方便,这里说一下server版下的配置,毕竟做开发经常还是用server版的 1.安装 apt-get install alsa-ba ...
- 使用virtualenv, uwsgi, nginx来布署flask
本文讲述了怎样使用virtualenv, uwsgi, nginx来布署flask的步骤. 升级软件包 运行下面命令,保证你的机器安装了最新的软件包. sudo apt-get update sudo ...
- Python 005- 使用Pyecharts来绘制各种各样的图形
本文转载自:https://blog.csdn.net/qq_39143076/article/details/79065448,如有侵权,请联系删除啊 如何做Python 的数据可视化? pyech ...
- 开启 J2EE(六)— Servlet之Filter具体解释及乱码处理实例
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/akkzhjj/article/details/36471477 定义和功能 Filter:过滤器,它 ...
- 【转】idea激活搭建授权服务器
1.下载软件:磁力链接: magnet:?xt=urn:btih:2289E4F8CEB346AC44E54C8C0DA706CC537301AA 复制磁力链接地址 magnet:?xt=urn:bt ...
- oracle中的exists和not exists和in用法详解
in 是把外表和内表作hash 连接,而exists是对外表作loop循环,每次loop循环再对内表进行查询. not exists:做NL,对子查询先查,有个虚表,有确定值,所以就算子查询有NULL ...
- Hive 自定义函数 UDF UDAF UDTF
1.UDF:用户定义(普通)函数,只对单行数值产生作用: 继承UDF类,添加方法 evaluate() /** * @function 自定义UDF统计最小值 * @author John * */ ...