Dating with girls(1)

Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3869    Accepted Submission(s): 1196

Problem Description
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.
 
Output
For each cases,output the numbers of solutions to the equation.
 
Sample Input
2
5 4
1 2 3 4 5
8 8
1 4 5 7 8 9 2 6
 
Sample Output
3
5
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  2575 2579 2573 2576 2574
 
要去除重复的元素和大于k的元素,因为大于k的元素是肯定组不成等于k的方程的,不能确定数据里是否有0,所以等于k的元素也保留着,每存一个数都hash一下,然后一遍for循环,看 hash[ k-a[i] ]是否为1,是的话cnt++;
 #include<queue>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 123456
#define M 1234 int n,k;
int a[N];
int main()
{
int t;cin>>t;
while(t--)
{
scanf("%d%d",&n,&k);
int ha[N]={};
int j=,c;
for(int i=;i<n;i++)
{
scanf("%d",&c);
if(c>k || ha[c])continue;
a[j++]=c;
ha[c]=;
}
int cnt=;
for(int i=;i<j;i++)
if(ha[ k-a[i] ])
cnt++; cout<<cnt<<endl;
}
return ;
}

HDU 2578 Dating with girls(1) [补7-26]的更多相关文章

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

  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 2578 Dating with girls(1) (hash)

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

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

  7. Dating with girls(1)(二分+map+set)

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

  8. 二分-B - Dating with girls(1)

    B - Dating with girls(1) Everyone in the HDU knows that the number of boys is larger than the number ...

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

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

随机推荐

  1. centos中python2替换为python3,并解决yum出错

    这里采用安装python3.6版本. 安装python3.6可能使用的依赖 yum install openssl-devel bzip2-devel expat-devel gdbm-devel r ...

  2. xhtml css 漏 整理

    1)文档类型 代码最上部有如下这句话: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &quo ...

  3. google F12

    谷歌浏览器(Google Chrome)开发调试详细介绍 博客分类: 前端 浏览器chromegoogle调试开发  很多Web前台开发者都喜欢这种浏览器自带的开发者工具,这对前台设计.代码调试很大帮 ...

  4. java 获取音频文件时长

    需要导入jar包:jave 1.0.2 jar 如果是maven项目,在pom.xml文件中添加: <dependency> <groupId>it.sauronsoftwar ...

  5. Python开发:网络编程

    Python 提供了两个级别访问的网络服务.: 低级别的网络服务支持基本的 Socket,它提供了标准的 BSD Sockets API,可以访问底层操作系统Socket接口的全部方法. 高级别的网络 ...

  6. Java列出接口实现的所有接口

    package com.tj; public class MyClass2 { public static void main(String[] args) { Class cls = java.ut ...

  7. Windows同步阿里云时间

    Ctrl+R打开cmd命令框 输入:gpedit.msc 计算机配置”—“管理模版”—“系统”—“Windows 时间服务”—“时间提供程序”—“配置 Windows NTP 客户端 双击打开配置 W ...

  8. HDU-4847 Wow! Such Doge!,模拟!

    Wow! Such Doge! 题意:给定的字符串中doge出现了多少次,直接模拟即可,不用KMP. char s[N]; int main() { // int n; int ans=0; whil ...

  9. 九度oj 题目1048:判断三角形类型

    题目描述: 给定三角形的三条边,a,b,c.判断该三角形类型. 输入: 测试数据有多组,每组输入三角形的三条边. 输出: 对于每组输入,输出直角三角形.锐角三角形.或是钝角三角形. 样例输入: 3 4 ...

  10. Terracotta2

    Terracotta 3.2.1简介 (二) Terracotta分布式缓存EhcacheQuartzTerracotta的web session方案  高效.高可用的Web Session解决方案 ...