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)的更多相关文章

  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 ...

  2. hdu 2578 Dating with girls(1)

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2578 Dating with girls(1) Description Everyone in the ...

  3. 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+ ...

  4. 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 ...

  5. hdu 2579 Dating with girls(2)

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2579 Dating with girls(2) Description If you have sol ...

  6. hdoj 2579 Dating with girls(2)【三重数组标记去重】

    Dating with girls(2) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. ssh远程连接到Ubuntu

    1.ubuntu首先得安装ssh sudo apt-get install openssh-server 2.启动ssh sudo /etc/init.d/ssh start 3.检查是否开启 ps ...

  2. 802.11 MAC基础

    MAC(媒介访问控制层)位于各式物理层之上,控制数据的传输.它负责核心成帧操作以及与有线骨干网络之间的交互. 802.11采用载波监听多路访问/冲突避免(CSMA/CA)机制来控制对传输媒介的访问. ...

  3. 在Idea中jdk11和jdk8环境变量的切换

    先配置好jdk11和jdk8环境变量 idea(2019.3)中jdk版本切换(jdk8和jdk11) 快捷键ctrl + shift + alt +s ,将jdk11修改为jdk1.8 完成后,显示 ...

  4. 【DTOJ】2703:两个数的余数和商

    DTOJ 2703:两个数的余数和商  解题报告 2017.11.10 第一版 ——由翱翔的逗比w原创,引用<C++ Primer Plus(第6版)中文版> 题目信息: 题目描述 给你a ...

  5. (未完成)【Android】MVP模式初见(一)

    最近在阅读郭霖大神的公众号时,分类中架构引起了我的注意. 虽然是个人开发(水平很菜的那种),但最终都要向企业正式项目开发靠近.因此接下来一段时间,主要学习一下MVP架构.Retrofit以及RxJav ...

  6. 企业应用开发的大趋势,65%的应用开发将通过低代码完成 ZT

    全球知名的咨询公司Gartner于近日发表了最新版的<低代码开发平台魔力象限>,并在报告中指出,到2024年65%的应用开发工作都将通过低代码的方式完成.Gartner长期关注软件开发领域 ...

  7. 开发者的拯救者还是掘墓人?解密低代码开发平台 ZT

    据英国<金融时报>消息称,私募股权投资机构 KKR 和高盛共同筹集了 3.6 亿美元,以收购低代码开发平台 OutSystems 的“大量”少数股权,本次交易对 OutSystems 的估 ...

  8. docker - apt-get更换国内源解决Dockerfile构建速度过慢

    背景 使用ubuntu镜像一般apt-get源地址都是在国外导致在构建时因为源地址问题导致下载速度极其得慢 在构建中应事先修改apt-get源地址来避免因下载速度过慢导致的构建缓慢问题 方案 在Doc ...

  9. Mac 配置本地SSL

    1,执行: && openssl req -new -sha256 -x509 -days -key server.key -out server.crt 2,生成过程中,其它可随便填 ...

  10. Jekyll 摘要

    在 Windows 上安装 Requirements Permalink Ruby version 2.4.0 or above, including all development headers ...