HDU 2141 二分查找
来源:互联网 发布:php 链接ftp源码 编辑:程序博客网 时间:2024/06/06 02:13
Can you find it?
Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/Others)Total Submission(s): 18190 Accepted Submission(s): 4600
Problem Description
Give you three sequences of numbers A, B, C, then we give you a number X. Now you need to calculate if you can find the three numbers Ai, Bj, Ck, which satisfy the formula Ai+Bj+Ck = X.
Input
There are many cases. Every data case is described as followed: In the first line there are three integers L, N, M, in the second line there are L integers represent the sequence A, in the third line there are N integers represent the sequences B, in the forth line there are M integers represent the sequence C. In the fifth line there is an integer S represents there are S integers X to be calculated. 1<=L, N, M<=500, 1<=S<=1000. all the integers are 32-integers.
Output
For each case, firstly you have to print the case number as the form "Case d:", then for the S queries, you calculate if the formula can be satisfied or not. If satisfied, you print "YES", otherwise print "NO".
Sample Input
3 3 31 2 31 2 31 2 331410
Sample Output
Case 1:NOYES#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>using namespace std;int search(int val,int len);int a[555]={0},b[250001]={0},c[555]={0};int main(){int A=0,B=0,C=0;int kkk=1;while(scanf("%d%d%d",&A,&B,&C)!=EOF){int t=0;memset(a,0,sizeof(a));memset(b,0,sizeof(b));memset(c,0,sizeof(c));for(int i=0;i<A;i++) scanf("%d",&a[i]);for(int i=0;i<B;i++){int x=0;scanf("%d",&x);for(int j=0;j<A;j++){b[t++]=x+a[j];}}for(int i=0;i<C;i++) scanf("%d",&c[i]);sort(b,b+t);int s=0;scanf("%d",&s);int X[1005]={0};for(int kk=1;kk<=s;kk++){ scanf("%d",&X[kk]);}printf("Case %d:\n",kkk++);for(int kk=1;kk<=s;kk++){bool mark=0;for(int i=0;i<C;i++){if(search(X[kk]-c[i],t)){printf("YES\n");mark=1;break;}} if(!mark) printf("NO\n");}}return 0;}int search(int val,int len){int l=0,r=len-1,mid;while(l<=r){mid=(l+r)/2;if(b[mid]<val)l=mid+1;else if(b[mid]==val){return 1;}else r=mid-1;}return 0;}
0 0
- hdu 2141 二分查找
- hdu 2141 二分查找
- HDU 2141 二分查找
- HDU 2141 二分查找
- HDU 2141 二分查找
- 二分查找(HDU 2141 )
- HDU-2141(二分查找)
- HDU-2141(二分查找_创新)
- hdu 2141 二分查找,三个数相加
- hdu 2141(二分查找,合并数组)
- hdu 2141 枚举后 二分查找
- hdu 1969 二分查找
- HDU-2199 二分查找
- 二分查找 hdu 4004
- hdu 1597 二分查找
- hdu 5178 二分查找
- hdu 5178 二分查找
- HDU 2199 二分查找
- 类内成员变量直接初始化小记
- Java抽象类与接口的总结
- javaAPI文档翻译之Java.io.File
- 原型模式实现
- C++ <sstream>学习
- HDU 2141 二分查找
- 【QT5学习历程】
- easyui 之 data-option
- USACO 2.2 Subset Sums (DP动态规划)
- php move_uploaded_file()函数
- (通俗易懂)自定义代理 :传递(参数)
- 感悟
- java中对字符串的基本操作
- hdu 2594 Simpsons’ Hidden Talents