hdu 2578 Dating with girls(1) (hash)
Dating with girls(1)
Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2127 Accepted Submission(s): 730
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!

5 4
1 2 3 4 5
8 8
1 4 5 7 8 9 2 6
5
//1968MS 2000K 551 B G++
//1421MS 1932K 551 B C++
/* 题意:
给你n个数,和一个数k,问n个数中有多少d对不同的x、y使
x+y=k 成立
x可以等于y hash:
直接使用C++的map容器做映射。
注意一点就是要排序,避免出现相同的x、y */
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int main(void)
{
int t,n,k,a[];
scanf("%d",&t);
while(t--)
{
map<int,int>M;
M.clear();
scanf("%d%d",&n,&k);
for(int i=;i<n;i++){
scanf("%d",&a[i]);
if(M[a[i]]==) M[a[i]]=;
}
sort(a,a+n);
int ans=;
a[n]=-;
for(int i=;i<n;i++)
if(M[k-a[i]]== && a[i]!=a[i+]) ans++;
printf("%d\n",ans);
}
return ;
}
hdu 2578 Dating with girls(1) (hash)的更多相关文章
- 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)
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2578 Dating with girls(1) Description Everyone in the ...
- 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 ...
- 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 ...
- 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 ...
- Dating with girls(1)(二分+map+set)
Dating with girls(1) Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- 二分-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 ...
- hdoj 2579 Dating with girls(2)【三重数组标记去重】
Dating with girls(2) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
随机推荐
- SpringBoot学习11:springboot异常处理方式1(自定义异常页面)
SpringBoot 默认的处理异常的机制:SpringBoot 默认的已经提供了一套处理异常的机制.一旦程序中出现了异常 SpringBoot 会向/error 的 url 发送请求.在 sprin ...
- windows tensorflow 简单安装
需要64位系统windows, 下载64位的python3.5 官网下载地址:https://www.python.org/downloads/release/python-352/ 百度云下载地址: ...
- BZOJ1050: [HAOI2006]旅行comf(并查集 最小生成树)
Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 4021 Solved: 2257[Submit][Status][Discuss] Descript ...
- C/C++程序基础 (十一)标准模板库
标准模板库 标准模板库在标准函数库的定位 迭代器(类似指针)保证算法(常用算法)和容器(数据结构)的结合. vector的实现 底层实现是动态数组,所以支持随机访问. 内部是动态数组,随着insert ...
- 局域网内使用ssh连接两台计算机总结
因为家里有两台电脑,一个centos7 系统,一个Mac,都是笔记本,感觉两个拿来拿去的用太麻烦了,所以就想用ssh连接cenots7 的电脑,这样就没那么麻烦了.欢迎大家指正 配置静态ip cent ...
- 【牛客 错题集】Linux系统方面错题合集
前言:牛客Linux322道全部刷完,有些题目较老,甚至考核5系统,现在7都出来了几年了 = = 还有些题目解析的很好部分也摘录了进来.很多涉及嵌入式开发的选择题同样的摘录的作为了解使用 ------ ...
- 史上最强大的wordpress后台框架redux-framework安装及使用
redux-framework的相关链接 Redux的官方网站:https://reduxframework.com/ Redux文档查询:https://docs.reduxframework.co ...
- google云函数实现BigQuery数据操作
Google Cloud Function操作BigQuery数据库. 1.部署云函数时在配置文件中(package.json)添加一项 "@google-cloud/bigquery&qu ...
- hdoj 1237 模拟
计算器 Problem Description 读入一个只包含 +, -, *, / 的非负整数计算表达式,计算该表达式的值. Input 测试输入包含若干测试用例,每个测试用例占一行,每行不超过 ...
- 真是shi
降雨量那题,真踏马shi. 调到还有五个RE不调了. 开始以为map可水后来发现一定要二分查找一下. 这种题没啥营养,不过我发现了我ST表一处错误并打了个板子.就这点用处吧. 这几天做题太少了,每天不 ...