HDU
来源:互联网 发布:seo关键词优化工具 编辑:程序博客网 时间:2024/05/20 20:44
题目链接:HDU - 2141:Can you find it?
题意:给你三组数,要你各从三组数中挑出一个,满足
思路:典型的二分搜索,先A、B求和并排序,然后二分搜索ab=x-c
AC代码:
#include<iostream>#include<cstdio>#include<algorithm>#define maxn 510using namespace std;int a[maxn],b[maxn],c[maxn],ab[maxn*maxn];int L,N,M,k;bool judge(int x){ int left=0,right=k-1; while(left<=right) { int mid=(left+right)>>1; if(ab[mid]<x) left=mid+1; else if(ab[mid]>x) right=mid-1; else return true; } return false;}int main(){ int cas=1; while(~scanf("%d%d%d",&L,&N,&M)) { printf("Case %d:\n",cas++); for(int i=0; i<L; i++) scanf("%d",&a[i]); for(int i=0; i<N; i++) scanf("%d",&b[i]); for(int i=0; i<M; i++) scanf("%d",&c[i]); k=0; for(int i=0; i<L; i++) for(int j=0; j<N; j++) ab[k++]=a[i]+b[j]; sort(ab,ab+k); int s,x; scanf("%d",&s); while(s--) { int flag=0; scanf("%d",&x); for(int j=0; j<M; j++) { int y=x-c[j]; if(judge(y)) {flag=1;break;} } if(flag) printf("YES\n"); else printf("NO\n"); } } return 0;}
阅读全文
0 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- 跳台阶 java实现
- SnailApp项目---路由框架搭建
- 51nod 1109 01组成的N的倍数
- 误删linux下passwd目录导致进不去系统
- 选择排序
- HDU
- DBA必备脚本--检查失败的作业
- CloudStack相关技术-Zone
- 剑指offer面试题目:第一个只出现一次的字符
- 实现将字符串右循环n位
- 1002. A+B for Polynomials (25)
- SnailApp项目---网络请求封装
- Microsoft Office Plus 2016专业增强版激活
- mybatis从入门到精通