POJ2366【二分】
题意:
给两个序列,问两个序列中是否有两个数加起来=1e4;
思路:
直接先排序好b序列,然后枚举a序列,二分查找b序列就好了;
贴一发挫code….
//#include <bits/stdc++.h>
#include<iostream>
#include<math.h>
#include<string.h>
#include<cstdio>
#include<algorithm>
using namespace std;
const float pi=acos(float(-1));
const int N=5e4+10;
int a[N];
int b[N];
int main()
{
int n,m;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
scanf("%d",&m);
for(int j=1;j<=m;j++)
scanf("%d",&b[j]);
sort(b+1,b+m+1);
int s,t,mid;
for(int i=1;i<=n;i++)
{
int x=10000-a[i];
// if(m==1)
// {
// if(b[m]==x)
// {
// printf("YES\n");
// return 0;
// }
// continue;
// }
s=1,t=m;
while(s<=t)
{
int mid=(s+t)/2;
if(b[mid]<x)
{
s=mid+1;
}
else if(b[mid]==x)
{
printf("YES\n");
return 0;
}
else
t=mid-1;
}
}
printf("NO\n");
return 0;
}
POJ2366【二分】的更多相关文章
- BZOJ1012: [JSOI2008]最大数maxnumber [线段树 | 单调栈+二分]
1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 8748 Solved: 3835[Submi ...
- BZOJ 2756: [SCOI2012]奇怪的游戏 [最大流 二分]
2756: [SCOI2012]奇怪的游戏 Time Limit: 40 Sec Memory Limit: 128 MBSubmit: 3352 Solved: 919[Submit][Stat ...
- 整体二分QAQ
POJ 2104 K-th Number 时空隧道 题意: 给出一个序列,每次查询区间第k小 分析: 整体二分入门题? 代码: #include<algorithm> #include&l ...
- [bzoj2653][middle] (二分 + 主席树)
Description 一个长度为n的序列a,设其排过序之后为b,其中位数定义为b[n/2],其中a,b从0开始标号,除法取下整. 给你一个长度为n的序列s. 回答Q个这样的询问:s的左端点在[a,b ...
- [LeetCode] Closest Binary Search Tree Value II 最近的二分搜索树的值之二
Given a non-empty binary search tree and a target value, find k values in the BST that are closest t ...
- [LeetCode] Closest Binary Search Tree Value 最近的二分搜索树的值
Given a non-empty binary search tree and a target value, find the value in the BST that is closest t ...
- jvascript 顺序查找和二分查找法
第一种:顺序查找法 中心思想:和数组中的值逐个比对! /* * 参数说明: * array:传入数组 * findVal:传入需要查找的数 */ function Orderseach(array,f ...
- BZOJ 1305: [CQOI2009]dance跳舞 二分+最大流
1305: [CQOI2009]dance跳舞 Description 一次舞会有n个男孩和n个女孩.每首曲子开始时,所有男孩和女孩恰好配成n对跳交谊舞.每个男孩都不会和同一个女孩跳两首(或更多)舞曲 ...
- BZOJ 3110 [Zjoi2013]K大数查询 ——整体二分
[题目分析] 整体二分显而易见. 自己YY了一下用树状数组区间修改,区间查询的操作. 又因为一个字母调了一下午. 貌似树状数组并不需要清空,可以用一个指针来维护,可以少一个log 懒得写了. [代码] ...
随机推荐
- Android studio 导入githubproject
Blog From:http://blog.csdn.net/onlysnail/article/details/45115093 从github下载两个开源项目: PagerSlidingTabSt ...
- RecyclerView的万能切割线
效果图: 用法: 加入默认切割线:高度为2px.颜色为灰色 mRecyclerView.addItemDecoration(new RecycleViewDivider(mContext, Linea ...
- Linux内存管理之mmap详解 (可用于android底层内存调试)
注:将android底层malloc换为mmap来获取内存,可将获取到的内存添加tag,从而再利用meminfo进行分析,可单独查看该tag的内存,从而进行分析. 一. mmap系统调用 1. mma ...
- hdu 1250 Hat's Fibonacci
pid=1250">点击此处就可以传送hdu 1250 Problem Description A Fibonacci sequence is calculated by adding ...
- hdoj-3371-Connect the Cities【最小生成树】
Connect the Cities Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- Python 学习资料分享
有同学需要学习 Python,确实,随着人工智能被炒的火热,再加上大数据时代,作为程序员的我们,怎么可能坐得住,必须尝尝鲜,给自己增加一项技能,增加自己的竞争了. 内容定位 这方面的学习资料比较多,本 ...
- sanic官方文档解析之下载和Configuration
1,sanic框架是做什么的? sanic的官方网址:https://sanic.readthedocs.io/en/latest/ sanic框架是一个类似于flask框架的在Python3.5以上 ...
- camus gobblin
####Camus is being phased out and replaced by Gobblin. For those using or interested in Camus, we su ...
- 正则_action
http://wiki.ubuntu.org.cn/index.php?title=Python%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E6%93% ...
- group by where having 联合使用
having子句与where有相似之处但也有区别,都是设定条件的语句.在查询过程中聚合语句(sum,min,max,avg,count)要比having子句优先执行.而where子句在查询过程中执行优 ...