杭电 2141 Can you find it?二分法+暴力查找
来源:互联网 发布:在职研究生研修班 知乎 编辑:程序博客网 时间:2024/05/23 15:09
Can you find it?
Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/Others)
Total Submission(s): 17174 Accepted Submission(s): 4362
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:NOYESNO
给出ABC三个数列,再给出S个X,问在数列中是否有元素满足Ai+Bj+Ck=X。
程式需优化,即A+B=X-C。
另外:输出一定要注意都是大写啊啊啊啊啊。。。WA了一下午快哭了。。。
#include<stdio.h>#include<algorithm>#define max 500using namespace std;int a[max+10],b[max+10],c[max+10],ab[max*max+10];int main(){int l,m,n,t=0,s,x;while(~scanf("%d%d%d",&l,&n,&m)){int i,j,k=0,flag=0;for(i=0;i<l;i++) scanf("%d",&a[i]);for(i=0;i<n;i++) scanf("%d",&b[i]);for(i=0;i<m;i++) scanf("%d",&c[i]);for(i=0;i<l;i++){for(j=0;j<n;j++){ab[k++]=a[i]+b[j];}}sort(ab,ab+k);sort(c,c+m);scanf("%d",&s);printf("Case %d:\n",++t);while(s--){int flag=0;scanf("%d",&x);int p,q;for(i=0;i<m;i++){p=x-c[i];q=lower_bound(ab,ab+k,p)-ab;if(p==ab[q]) flag=1;}if(flag) printf("YES\n"); else printf("NO\n"); }}return 0;}
0 0
- 杭电 2141 Can you find it?二分法+暴力查找
- 杭电2141-Can you find it?
- 杭电2141Can you find it?
- 杭电2141Can you find it?
- 【杭电】[2141]Can you find it?
- 【杭电2141】Can you find it?
- 【杭电2141】Can you find it?
- hdoj 2141 Can you find it? 【二分法】
- 二分法-Can you find it?
- 杭电5478Can you find it
- 杭电 HDU 2141 Can you find it
- HDU--杭电--2141--Can you find it?--二分
- hdu 2141 Can you find it?(二分法)
- HD2141 Can you find it? 【二分法求解】
- hdu 2141 Can you find it?(暴力+二分)
- HDU 2141 Can you find it?(暴力+二分)
- [HDU](2141)Can you find it? ---二分查找(查找)
- H电-Problem Archive-2141-Can you find it?
- 教你如何迅速秒杀掉:99%的海量数据处理面试题
- UI01_UIView
- BZOJ 2208 [Jsoi2010]连通数 tarjan缩点+bitset优化DP
- 怎样VS2013下安装Qt5的插件
- flexpaper全屏缩放后 浏览器滚动条失效
- 杭电 2141 Can you find it?二分法+暴力查找
- HDU 5336 XYZ and Drops
- RSA ENCRYPT
- Codeforces Round #124 (Div. 2)
- final变量
- select用法详解 http://blog.chinaunix.net/uid-23373524-id-2426940.html
- 【数据结构】红黑树
- hdu5328 最长的连续的等比或等差数列
- 从字节码指令看重写在JVM中的实现