二分-B - Dating with girls(1)
Everyone in the HDU knows that the number of boys is larger than the number of girls. But now, every boy wants to date with pretty girls. The girls like to date with the boys with higher IQ. In order to test the boys ' IQ, The girls make a problem, and the boys who can solve the problem
correctly and cost less time can date with them.
The problem is that : give you n positive integers and an integer k. You need to calculate how many different solutions the equation x + y = k has . x and y must be among the given n integers. Two solutions are different if x0 != x1 or y0 != y1.
Now smart Acmers, solving the problem as soon as possible. So you can dating with pretty girls. How wonderful!Input
The first line contain an integer T. Then T cases followed. Each case begins with two integers n(2 <= n <= 100000) , k(0 <= k < 2^31). And then the next line contain n integers.
Outpu
tFor each cases,output the numbers of solutions to the equation.
#include<iostream>
#include<algorithm>
using namespace std; int main(){
int T;
scanf("%d",&T);
while(T--){
int n,k,a[],cnt=;
scanf("%d %d", &n, &k);
for(int i=;i<n;i++)
scanf("%d", a+i);
sort(a,a+n);
for(int i=; i<n; i++){
int left = , right= n-;
while(right > left){
int mid = (left + right)/;
if(a[i] + a[mid] > k) right = mid-;
else if(a[i] + a[mid] < k) left = mid+;
else{
left = mid;
break;
}
}
if(a[i]+a[left]==k){
cnt++;
if(i!=&&a[i]==a[i-]) cnt--;
}
}
printf("%d\n",cnt);
}
}
二分-B - Dating with girls(1)的更多相关文章
- Dating with girls(1)(二分+map+set)
Dating with girls(1) Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- hdu 2578 Dating with girls(1)
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2578 Dating with girls(1) Description Everyone in the ...
- HDU 3784 继续xxx定律 & HDU 2578 Dating with girls(1)
HDU 3784 继续xxx定律 HDU 2578 Dating with girls(1) 做3748之前要先做xxx定律 对于一个数n,如果是偶数,就把n砍掉一半:如果是奇数,把n变成 3*n+ ...
- hdu 2578 Dating with girls(1) 满足条件x+y=k的x,y有几组
Dating with girls(1) Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- hdu 2579 Dating with girls(2)
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2579 Dating with girls(2) Description If you have sol ...
- hdoj 2579 Dating with girls(2)【三重数组标记去重】
Dating with girls(2) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- hdu 2579 Dating with girls(2) (bfs)
Dating with girls(2) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- hdu 2578 Dating with girls(1) (hash)
Dating with girls(1) Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU 2578 Dating with girls(1) [补7-26]
Dating with girls(1) Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
随机推荐
- k8s强制删除pod
有时候pod一直在Terminating kubectl delete pod xxx --force --grace-period=
- clr via c# delegate
1,委托列子 internal delegate void Feedback(int value); class DelegateRef { public static void StaticDele ...
- Resnet——深度残差网络(二)
基于上一篇resnet网络结构进行实战. 再来贴一下resnet的基本结构方便与代码进行对比 resnet的自定义类如下: import tensorflow as tf from tensorflo ...
- [CF1311C] Perform the Combo
Solution 前缀和搞一下即可 #include <bits/stdc++.h> using namespace std; #define int long long const in ...
- caj文件转word
转载:https://baijiahao.baidu.com/s?id=1590365105855177484&wfr=spider&for=pc 使用工具: 迅捷caj转word转换 ...
- linux安装最新(任意)版本nodejs
首先在终端中使用命令 uname -a 查看系统版本 uname -a x86_64 是64位的 所以要安装64位对应的nodejs 打开nodejs中文网里的下载 找到64位的文件 点击后就下载了 ...
- lvm实现服务器磁盘空间合并
1 LVM实现将2块磁盘总空间“合二为一”并挂载到同一目录 1.1 磁盘分区 首先查看磁盘信息,对未分区的磁盘进行分区处理(选择你要合并的盘,这里是对vdb.vdc). 如上图,可以看出有5 ...
- Swagger2 @ApiIgnore注解忽略接口在swagger-ui.html中显示
果项目中定义了一个controller,但是我们又不想把这个接口在swagger-ui.html中体现出来怎么办?不要着急,Swagger2已经替我们想到了这个问题,只要把@ApiIgnore放到你想 ...
- oracle基础知识点
一.count(*).count(1).count(字段名)的区别select count(*) from t_md_inst --153797 --包含字段为null 的记录select count ...
- js微信禁用右上角的分享按钮,和vue中微信页面禁用右上角的分享按钮的问题
1.隐藏微信网页右上角的按钮 document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() { // 通过下面这个 ...