题意:

给两个序列,问两个序列中是否有两个数加起来=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【二分】的更多相关文章

  1. BZOJ1012: [JSOI2008]最大数maxnumber [线段树 | 单调栈+二分]

    1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 8748  Solved: 3835[Submi ...

  2. BZOJ 2756: [SCOI2012]奇怪的游戏 [最大流 二分]

    2756: [SCOI2012]奇怪的游戏 Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 3352  Solved: 919[Submit][Stat ...

  3. 整体二分QAQ

    POJ 2104 K-th Number 时空隧道 题意: 给出一个序列,每次查询区间第k小 分析: 整体二分入门题? 代码: #include<algorithm> #include&l ...

  4. [bzoj2653][middle] (二分 + 主席树)

    Description 一个长度为n的序列a,设其排过序之后为b,其中位数定义为b[n/2],其中a,b从0开始标号,除法取下整. 给你一个长度为n的序列s. 回答Q个这样的询问:s的左端点在[a,b ...

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

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

  7. jvascript 顺序查找和二分查找法

    第一种:顺序查找法 中心思想:和数组中的值逐个比对! /* * 参数说明: * array:传入数组 * findVal:传入需要查找的数 */ function Orderseach(array,f ...

  8. BZOJ 1305: [CQOI2009]dance跳舞 二分+最大流

    1305: [CQOI2009]dance跳舞 Description 一次舞会有n个男孩和n个女孩.每首曲子开始时,所有男孩和女孩恰好配成n对跳交谊舞.每个男孩都不会和同一个女孩跳两首(或更多)舞曲 ...

  9. BZOJ 3110 [Zjoi2013]K大数查询 ——整体二分

    [题目分析] 整体二分显而易见. 自己YY了一下用树状数组区间修改,区间查询的操作. 又因为一个字母调了一下午. 貌似树状数组并不需要清空,可以用一个指针来维护,可以少一个log 懒得写了. [代码] ...

随机推荐

  1. 经典游戏“大富翁4”存档文件修改器Rich4Editor下载

    下载地址: http://files.cnblogs.com/files/xiandedanteng/Rich4Editor20170614.zip http://files.cnblogs.com/ ...

  2. Python--学习过程

    基础篇 Python基础篇 Python的数据类型 作业总结

  3. hunnu--11545--小明的烦恼——找路径

    小明的烦恼--找路径  Time Limit: 2000ms, Special Time Limit:5000ms, Memory Limit:32768KB Total submit users:  ...

  4. Ubuntu 16.04 LTS 配置 Jupyter notebook 为服务器

    原材料: Ubuntu 16.04 LTS 64bit 已经配置好 IPython 和 Jupyter (安装步骤可以参照:http://www.cnblogs.com/McKean/p/619497 ...

  5. angularjs学习之八(angularjs中isolate scope的使用)

    angular js中指令directive有个特别实用的东西,那就是 isolate scope (被隔离的scope) 关于详细他和全局的scope 有什么差别.能够參考以下这篇博文: Angul ...

  6. CXF发布在Web服务

    1.下载apache-cxf-3.1.4,将jar引入新工程中. 2.People.java package com.soap.server; import java.util.Date; impor ...

  7. Java获取域名

    private static final char URL_SPLASH = '/'; private static final String URL_SCHEME_POSTFIX = ": ...

  8. ARC机制之__strong具体解释

    ARC机制之__strong具体解释 __strong  解析: 默认情况下,一个指针都会使用 __strong 属性,表明这是一个强引用.这意味着,仅仅要引用存在,对象就不能被销毁.这是一种所期望的 ...

  9. How do I set the timeout for a JAX-WS webservice client?

    How do I set the timeout for a JAX-WS webservice client? up vote58down votefavorite 27 I've used JAX ...

  10. android checkbox radiogroup optionmenu dialog

    \n换行 UI visible:View.INVISIBLE 不可见,占用空间,View.GONE  不可见,不占用空间 菜单 res右击新建menu xml 自动新建menu文件夹 context ...