HDU2141-Can you find it?
来源:互联网 发布:递归算法反汇编 编辑:程序博客网 时间:2024/06/17 18:06
Can you find it?
Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/Others)
Total Submission(s): 29478 Accepted Submission(s): 7353
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 3
1 2 3
1 2 3
1 2 3
3
1
4
10
Sample Output
Case 1:
NO
YES
NO
Author
wangye
Source
HDU 2007-11 Programming Contest
题目大意:给出ABC三个数组,判断能否找到一个三元组满足Ai+Bi+Ci=X
解题思路:求出A+B,并排序,二分查找X-Ci
#include<iostream>#include<cstring>#include<cmath>#include<ctime>#include<cstdlib>#include<algorithm>#include<iomanip>#include<fstream>#include<map>using namespace std;const int MAXN=510;const int MAXM=250005;int a[MAXN],b[MAXN],c[MAXN];int d[MAXM];int k;bool bs(int key){ int L=1,R=k; int M; while(L<=R) { M=(L+R)/2; if(key==d[M]) return true; else if(key<d[M]) R=M-1; else L=M+1; } return false;}int main(){ int L,N,M; int s; int cas=1; while(cin>>L>>N>>M) { for(int i=1;i<=L;i++) { cin>>a[i]; } for(int i=1;i<=N;i++) { cin>>b[i]; } for(int i=1;i<=M;i++) { cin>>c[i]; } k=0; for(int i=1;i<=L;i++) { for(int j=1;j<=N;j++) { k++; d[k]=a[i]+b[j]; } } sort(d+1,d+k+1); /*for(int i=1;i<=k;i++) cout<<d[i]<<" "; cout<<endl;*/ cin>>s; int x; cout<<"Case "<<cas++<<":"<<endl; for(int i=1;i<=s;i++) { cin>>x; bool flag=false; for(int i=1;i<=M;i++) { if(bs(x-c[i])) { flag=true; break; } } if(flag) cout<<"YES"<<endl; else cout<<"NO"<<endl; } }}
- HDU2141 Can you find it?
- HDU2141-Can you find it?
- HDU2141-Can you find it?
- Can you find it? hdu2141 二分查找
- HDU2141:Can you find it?(二分)
- 二分 hdu2141 Can you find it?
- hdu2141 Can you find it?(二分*)
- HDU2141 Can you find it?(二分)
- HDU2141:Can you find it? (二分)
- hdu2141 Can you find it? (二分)
- HDU2141 Can you find it?(二分)
- hdu2141 Can you find it? (二分查找)
- HDU2141:Can you find it?(二分 + 优化)
- HDU2141.Can you find it?——不同的二分不同的TLE
- CSU-ACM2017暑假集训2-二分搜索 hdu2141- Can you find it?
- can you find it?
- Can you find it?
- Can you find it?
- iOS路由跳转(四)之JKRouter持续更新1
- idea添加其他包的方法
- Java 中的 static 使用之静态方法
- Leetcode Algorithm 005. Longest Palindromic Substring
- 基于Mojo的perl爬虫
- HDU2141-Can you find it?
- 如何访问一个控件的 Protected 段的成员,改变 DBNavigator 的行为
- 夜间车辆识别
- LeetCode (Set Matrix Zeroes)
- 计算一个字符串中的字串
- $.ajax()引发的对Deferred的总结
- Java环境配置
- 获取天气预报的小爬虫
- javascript生成32位UUID的方法