Can you find it?

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

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
 
lower_bound提交就会出错,binary_search()也可以过
  1. #include <iostream>
  2. #include <cstring>
  3. #include <cstdio>
  4. #include <algorithm>
  5. #include <set>
  6. using namespace std;
  7. int a[],b[],c[],x;
  8. __int64 su[*];
  9. int l,n,m,s,u;
  10. int d=,sum;
  11. bool solve(int x)
  12. {
  13. int i,k;
  14. int ans;
  15. for(i=;i<m;i++)
  16. {
  17. ans=x-c[i];
  18. int l=,r=u-,mid,e;
  19. while(l<=r)
  20. {
  21. mid=(l+r)/;
  22. if(su[mid]==ans) return ;
  23. else if(su[mid]>ans) r=mid-;
  24. else l=mid+;
  25. }
  26. }
  27. return ;
  28. }
  29. int main()
  30. {
  31. int i,j;
  32. freopen("in.txt","r",stdin);
  33. while(scanf("%d%d%d",&l,&n,&m)!=EOF)
  34. {
  35. for(i=;i<l;i++) scanf("%d",&a[i]);
  36. for(i=;i<n;i++) scanf("%d",&b[i]);
  37. for(i=;i<m;i++) scanf("%d",&c[i]);
  38. scanf("%d",&s);
  39. u=;
  40. for(i=;i<l;i++)
  41. for(j=;j<n;j++)
  42. su[u++]=a[i]+b[j];
  43. sort(su,su+u);
  44. printf("Case %d:\n",d++);
  45. for(i=;i<s;i++)
  46. {
  47. scanf("%d",&x);
  48. if(solve(x)) printf("YES\n");
  49. else printf("NO\n");
  50. }
  51. }
  52. }

Can you find it?(hdu 2141 二分查找)的更多相关文章

  1. Equations(hdu 1496 二分查找+各种剪枝)

    Equations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  2. Pie(hdu 1969 二分查找)

    Pie Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  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/Others ...

  5. 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 ...

  6. 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 ...

  7. HDU 2141 Can you find it?【二分查找是否存在ai+bj+ck=x】

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

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

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

  9. 二分查找 HDOJ 2141 Can you find it?

    题目传送门 /* 题意:给出一个数,问是否有ai + bj + ck == x 二分查找:首先计算sum[l] = a[i] + b[j],对于q,枚举ck,查找是否有sum + ck == x */ ...

随机推荐

  1. AI自动寻路

    1.首先把游戏场景中的物体设为静态 2.选中Window 中的Navigation ,点击Bake进行场景烘焙 3.在需要寻路的游戏对象上添加 NavMeshAgent组件.调整其AgentSize大 ...

  2. sgu Ice-cream Tycoon

    题意:供应商提供n块价格为c的冰淇淋,一个学生想买n块冰淇淋,手中的钱数总共有t元,为了不让买n块冰淇淋所花费的钱数不超过t元,先尽可能卖给这个学生便宜的冰淇淋. 如果这个学生不能买到所需要的冰淇淋则 ...

  3. jQuery对象转换为DOM对象

    第一种方法:借助数组下标来读取jQuery对象集合中的某个DOM元素对象. <script src="Scripts/jquery-1.4.1.js" type=" ...

  4. 【转】git 学习笔记( 随时更新中…… 最后更新日期201304281518)--不错

    原文网址:http://blog.csdn.net/yasin_lee/article/details/5975070 GIT 是版本管理的未来!   推荐几个GIT教程网站 http://www-c ...

  5. Hdu2437-Jerboas(取余数判重搜索)

    Jerboas are small desert-living animals, which resemble mice with a long tufted tail and very long h ...

  6. 【转】关于android应用程序的入口

    android应用程序,由一到多个Activity组成.每个Activity没有很紧密的联系,因为我们可以在自己的程序中调用其它Activity,特别是调用自己的代码之外生成的Activity,比如a ...

  7. codevs 1001 舒适的路线 (并查集)

    题目描述 Description Z小镇是一个景色宜人的地方,吸引来自各地的观光客来此旅游观光. Z小镇附近共有 N(<N≤)个景点(编号为1,,,…,N),这些景点被M(<M≤)条道路连 ...

  8. NavMeshAgent 动态加载障碍物

    如果你想让游戏人物绕开一些物体, 这些物体动态生成出来的.只需要给物体添加NavMeshObstacle组件即可 1. 绿色方块添加NavMeshObstacle组件 2. 红色方块没有添加NavMe ...

  9. 分享一个3D球面标签云

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. [置顶] Java中发邮件的6种方法

    1.官方标准JavaMail Sun(Oracle)官方标准,功能强大,用起来比较繁琐. 官方资料:http://www.oracle.com/technetwork/java/javamail/in ...