Can you find it?

Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/10000 K (Java/Others)
Total Submission(s): 29184    Accepted Submission(s): 7286

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

题意:给出三个数列ABC,从ABC各取一个整数求是否能够等于X,是则输出YES,否NO。

三组500直接查找会超时

可将A+B+C=X转换为A+B=X-C

之后即可将等式两边看做两个整体进行二分查找。

AC代码:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int a[],b[],c[];
  5. int num[];
  6.  
  7. int bin(int q[],int x,int y){
  8. int left=,right=x,mid;
  9. while(left<=right){
  10. mid=(left+right)/;
  11. if(q[mid]==y)
  12. return ;
  13. if(q[mid]>y)
  14. right=mid-;
  15. else
  16. left=mid+;
  17. }
  18. return ;
  19. }
  20.  
  21. int main(){
  22. int l,n,m,s,ans=;
  23. while(cin>>l>>n>>m){
  24. ans++;
  25. for(int i=;i<l;i++){
  26. cin>>a[i];
  27. }
  28. for(int i=;i<n;i++){
  29. cin>>b[i];
  30. }
  31. for(int i=;i<m;i++){
  32. cin>>c[i];
  33. }
  34. cin>>s;
  35. int x,cnt=;
  36.  
  37. for(int i=;i<l;i++){
  38. for(int j=;j<n;j++){
  39. num[cnt++]=a[i]+b[j];
  40. }
  41. }
  42. sort(num,num+cnt);
  43. printf("Case %d:\n",ans);
  44. while(s--){
  45. cin>>x;
  46. int flag=;
  47. for(int i=;i<m;i++){
  48. int temp=x-c[i];
  49. if(bin(num,cnt-,temp)){
  50. cout<<"YES"<<endl;
  51. flag=;
  52. break;
  53. }
  54. }
  55. if(!flag)
  56. cout<<"NO"<<endl;
  57. }
  58. }
  59. return ;
  60. }

hdu-2141的更多相关文章

  1. hdu 2141 (二分)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=2141 Can you find it? Time Limit: 10000/3000 MS (Java/O ...

  2. hdu 2141 Can you find it?

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2141 Can you find it? Description Give you three sequ ...

  3. hdu 2141 Can you find it?(二分查找)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2141 题目大意:查找是否又满足条件的x值. 这里简单介绍一个小算法,二分查找. /* x^2+6*x- ...

  4. HDU 2141 Can you find it? (二分)

    题目链接: Can you find it? Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/10000 K (Java/ ...

  5. hdu 2141:Can you find it?(数据结构,二分查找)

    Can you find it? Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/10000 K (Java/Others ...

  6. hdu 2141 Can you find it? (二分法)

    Can you find it? Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/10000 K (Java/Others ...

  7. Can you find it?(hdu 2141 二分查找)

    Can you find it? Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/10000 K (Java/Others ...

  8. hdu 2141 Can you find it?(二分查找变例)

    Problem Description Give you three sequences of numbers A, B, C, then we give you a number X. Now yo ...

  9. HDU 2141 Can you find it? [二分]

    Can you find it? Give you three sequences of numbers A, B, C, then we give you a number X. Now you n ...

  10. Can you find it? HDU - 2141 (二分查找)

    Give you three sequences of numbers A, B, C, then we give you a number X. Now you need to calculate ...

随机推荐

  1. 基于RFS(robot framework selenium)框架模拟POST/GET请求执行自动化接口测试

    打开RIDE添加测试用例 如: Settings         Library Collections       Library RequestsLibrary       Test Cases ...

  2. C++入门一

    C++ 项目结构 Resource Files: 项目引用的位图文件,图标,窗口,光标等.比如,你的程序要生成一个exe文件,而文件的图标是你自定义的图标,那就要在这个工程里面添加Icon资源,添加一 ...

  3. upstart man

    man upstart nit(8) init(8) NAME init - Upstart process management daemon SYNOPSIS init [OPTION]... D ...

  4. find and xargs

    调整搜索深度 -mandepth 搜索当前目录,而不进入子目录: find . -maxdepth 0 -name "debug*" Linux中find常见用法示例 ·find  ...

  5. kubernetes之常见故障排除(一)

    系列目录 由由种种原因,在安装或者使用kubernetes的过程中,可能会遇到各种各样的问题.本篇按照官网的介绍罗列出一些常见的故障,以帮助快速解决一些常见的错误. 安装赛程中出现ebtables o ...

  6. Apache Server与多个独立Tomcat集成

    取经自http://www.ramkitech.com/2012/03/virtual-host-apache-httpd-server-tomcat.html 继续干Tomcat和Apache Se ...

  7. SegmentFault 巨献 1024 程序猿游戏「红岸的呼唤」第二天任务攻略

    眼看实验室就要关门了.走之前写一下解题过程(事实上大家都等着第三题出来吧大概-=). 高速传送门:http://segmentfault.com/game/2 那么接昨天的博客,今天的题目是这种: 完 ...

  8. 继承的文本框控件怎么响应EN_CHANGE等消息

    继承的文本框控件如何响应EN_CHANGE等消息?我从CEdit继承了一个CMyEdit类,想在这个类里填写它的一些消息.我在消息映射表里写的是MESSAGE_HANDLER(EN_CHANGE, O ...

  9. mysql 中的增改查删(CRUD)

    增改查删可以用CURD来表示  增加:create  修改:update   查找:read      删除:delete 增加create :  insert +表名+values+(信息): in ...

  10. 我读过的最好的epoll讲解

        首先我们来定义流的概念,一个流可以是文件,socket,pipe等等可以进行I/O操作的内核对象.     不管是文件,还是套接字,还是管道,我们都可以把他们看作流.     之后我们来讨论I ...