题意:

给两个序列,问两个序列中是否有两个数加起来=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. c++ struct与class的差别

    从语法上,在C++中(仅仅讨论C++中).class和struct做类型定义时仅仅有两点差别: (一)默认继承权限. 假设不明白指定,来自class的继承依照private继承处理.来自struct的 ...

  2. [Binary Hacking] ABI and EABI

    Following are some general papers about ABI and EABI. Entrance https://en.wikipedia.org/wiki/Applica ...

  3. zoj 3573 Under Attack(线段树 标记法 最大覆盖数)

    Under Attack Time Limit:  10 Seconds      Memory Limit:  65536 KB  Doctor serves at a military air f ...

  4. java中简单字符替换

    在网络编程中,假设URL含有特殊字符,如空格.'#'等,server将无法识别导致无法获得正确的參数值.我们须要将这些特殊字符转换成server能够识别的字符,比如将空格转换成'%20'.给定一个字符 ...

  5. 甘特图——Excel搞定

    1. 甘特图 概念 甘特图就是条形图的一种. 甘特图是基于作业排序的目的,将活动与时间联系起来的最早尝试之中的一个. 这是什么意思呢?也就是说甘特图用来表示什么时间做什么事情,相当于一个计划安排.并且 ...

  6. Asp.net常用的51个代码(非常实用)

    1.//弹出对话框.点击转向指定页面 Response.Write("<script>window.alert('该会员没有提交申请,请重新提交!')</script> ...

  7. MFC 的 Picture Control 加载 BMP/PNG 图片的方法

    1. 加载 BMP CStatic* pWnd = (CStatic*)GetDlgItem(IDC_PIC); // 得到 Picture Control 句柄 pWnd->ModifySty ...

  8. 有遍历struct中字段信息的函数或方法

    例:struct a{int a;char b[10];double c;}; 在程序中只知道一个结构 a 的指针, 有没有函数能通过结构的名字 和 指向结构的指针 随次得到 结构中的变量类型 和 变 ...

  9. c++string 输入换行符

    string 一次只能输入一行,不含换行符.可以自己添加换行符 和输入行数.例如:#include <iostream>#include <string>using names ...

  10. gradle配置远程仓库(以及使用本地maven仓库)

    allprojects{ repositories { mavenLocal() def REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content ...