hdu2578(sort + 二分)
来源:互联网 发布:软件开发学习课程 编辑:程序博客网 时间:2024/06/05 20:08
思路:先sort一下,,,要找a + b = k,那么就枚举a二分查找b,然后就是判重;
点击题目链接
/*****************************************Author :Crazy_AC(JamesQi)Time :2015File Name :找两个数,a + b = k,枚举a,二分查找b;*****************************************/// #pragma comment(linker, "/STACK:1024000000,1024000000")#include <iostream>#include <algorithm>#include <iomanip>#include <sstream>#include <string>#include <stack>#include <queue>#include <deque>#include <vector>#include <map>#include <set>#include <stdio.h>#include <string.h>#include <math.h>#include <stdlib.h>#include <limits.h>using namespace std;#define MEM(a,b) memset(a,b,sizeof a)typedef long long LL;typedef unsigned long long ULL;typedef pair<int,int> ii;const int inf = 1 << 30;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;inline int Readint(){char c = getchar();while(!isdigit(c)) c = getchar();int x = 0;while(isdigit(c)){x = x * 10 + c - '0';c = getchar();}return x;}int a[100050];int bin(int x,int n){int low = 0,high = n - 1;while(low <= high){int mid = (low + high) >> 1;if (x < a[mid]) high = mid - 1;else if (x > a[mid])low = mid + 1;else return 1;//a[mid] == x;}return 0;//Not find;}int main(){// freopen("in.txt","r",stdin);// freopen("out.txt","w",stdout);int t;int n,k;scanf("%d",&t);while(t--){bool flag = true;scanf("%d%d",&n,&k);int ans = 0;for (int i = 0;i < n;i++)scanf("%d",&a[i]);sort(a,a + n);for (int i = 0;i < n;i++){if (bin(k - a[i],n)){ans++;if (i != 0 && a[i] == a[i - 1])//判重;ans--;}}printf("%d\n",ans);}return 0;}
0 0
- hdu2578(sort + 二分)
- HDU2578 Dating with girls(1)(二分)
- HDU2578 Dating with girls(1)(二分)
- HDU2578--Dating with girls(1) (map||排序+二分)
- HDU2578.Dating with girls(1)——二分
- hdu2578(二分法)
- Eqs(sort+二分)
- hdu5884 Sort(二分)
- hdu-Sort 二分
- poj 2153 map && sort+二分
- hdu5884 Sort(二分+K叉哈夫曼树)
- HDU 5884 Sort(哈夫曼树+二分)
- sort排序与二分查找
- HDU2578:Dating with girls(1)
- Sort 二分 + (队列 + sort 代替优先队列)
- HDU-5884-Sort-二分加多叉哈夫曼树
- HDU 5884 Sort(二分+单调队列)
- HDU 5884-Sort(队列+二分)
- Android打开/关闭蓝牙封装工具类
- mahout 返回主页 WEB系统架构与底层研发
- mahout探索推荐引擎内部的秘密
- POJ 3614 Sunscreen 多重匹配(网络流做法)
- mapreduce的debug
- hdu2578(sort + 二分)
- new DMS
- nutch + hbase 安装部署
- redis 添加访问密码
- redis3.0
- secondarynamenode配置使用总结
- Java虚拟机内存模型
- hdu5494 ( Card Game )
- setuid,setgid,sticky