hdu_2141_Can you find it?(二分)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2141
题意:叫你找三个数,使得这三个数的值为X,如果找得到就输出YES否则输出NO,注意两个32位数相加会爆int
#include<cstdio>
#include<algorithm>
using namespace std;
#define FFC(i,a,b) for(int i=a;i<=b;i++)
int L,N,M,t,ic=,x,l,r,mid,cnt;
long long a[],b[],c[],tmp[];
int lowb(long long *a,int x,int len){for(l=,r=len;l<=r;)if(a[mid=l+((r-l)>>)]>=x)r=mid-;else l=mid+;return l;}
int main(){
while(~scanf("%d%d%d",&L,&N,&M)){
printf("Case %d:\n",ic++);
FFC(i,,L)scanf("%lld",&a[i]);
FFC(i,,N)scanf("%lld",&b[i]);
FFC(i,,M)scanf("%lld",&c[i]);
cnt=;
FFC(i,,L)FFC(j,,N)tmp[++cnt]=a[i]+b[j];
sort(tmp+,tmp++cnt);
sort(c+,c++M);
scanf("%d",&t);
while(t--){
scanf("%d",&x);
if(x<c[]){puts("NO");continue;}
int fg=;
FFC(i,,M)if(tmp[lowb(tmp,x-c[i],cnt)]==x-c[i]){fg=;break;}
if(fg)puts("YES");
else puts("NO");
}
}
return ;
}
hdu_2141_Can you find it?(二分)的更多相关文章
- 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 懒得写了. [代码] ...
随机推荐
- python修炼7----迭代器
迭代器 -------------------------------------------------------------------------------- 充电小知识 1.yield-- ...
- $.ajax({})方法success,error,complete,beforeSend使用例子及解释
在与后台交互的时候,经常使用到jquery的$.ajax()方法来请求数据: 回调函数用的比较多的是success,但是complete.beforeSend.error函数也是很有用的: 下面是使用 ...
- Django 1.8 - “No migrations to apply” when run migrate after makemigrations 解决办法
解决办法 1 删除应用migrations目录 2 删除MySQL中django_migrations中对应的行(delete from django_migrations where app='ap ...
- MD5 .net与PHP加密值一样的加密代码
.net 代码 using System.Security.Cryptography; /// <summary> /// 返回大写形式的MD5加密 /// </summary> ...
- 关于Webapp的注意事项
meta标签 <meta name="viewport" content="width=device-width, initial-scale=1.0, user- ...
- PAT 团体程序设计天梯赛-练习集 L1-002. 打印沙漏
本题要求你写个程序把给定的符号打印成沙漏的形状.例如给定17个“*”,要求按下列格式打印 ***** *** * *** ***** 所谓“沙漏形状”,是指每行输出奇数个符号:各行符号中心对齐:相邻两 ...
- Apache Http Server和Tomcat 之区别
转自:Apache Http Server和Tomcat 之区别 Apache官方网站:http://www.apache.org/Tomcat官方网站:http://tomcat.apache.or ...
- 4、Spring+MyBatis增删改查
0.oracle数据库脚本 create table userinfo (id ), name ), password telephone ), isadmin )); --4.2 用户表序列 cre ...
- js技巧之this,call,apply
具体到实际应用中,this的指向又可以分为以下四种: 作为对象的方法调用 作为普通函数调用 构造器调用 apply和call调用 接下来我们去剖析前3点,至于第4点的apply和call调用,会在ca ...
- AVL树 高度平衡的二叉查找树
1.What is AVL tree? AVL tree 是一种特殊的二叉查找树,,首先我们要在树中引入平衡因子balance,表示结点右子树的高度减去左子树的高度差(右-左),对于一棵AVL树要么它 ...