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. 

InputThere 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. 
OutputFor 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

  1. 3 3 3
  2. 1 2 3
  3. 1 2 3
  4. 1 2 3
  5. 3
  6. 1
  7. 4
  8. 10

Sample Output

  1. Case 1:
  2. NO
  3. YES
  4. NO
  5.  
  6. 题目大意:输入3个数组,3个数组中的元素相加,判断是否能得到x
    题目的输入输出有点恶心人,,,写的时候弄的我晕 ,,哇了好几次
    思路 :一开始想到的是暴力枚举,,但是肯定会TLE 看了一下大佬们的博客,,用二分法方便一点 就是让A+B构成一个新的数组sumx-c[i]构成一个新的数组cc,然后在sum中查找是否存在cc中的元素有的话返回YES否则返回NO
    AC代码:(本人不太擅长二分所以代码质量不高)
  1. #include<iostream>
  2. #include<algorithm>
  3. using namespace std;
  4. int a[];
  5. int b[];
  6. int c[];
  7. int sum[*+];
  8. int pos;
  9. int judge(int x){
  10.  
  11. if(x<sum[]||x>sum[pos-]) return ;
  12.  
  13. int low=,high=pos-;
  14. while(low<=high){
  15. int mid=(high+low)/;
  16. // cout<<mid<<endl;
  17. if(sum[mid]>x){
  18. high=mid-;
  19. }
  20. else if(sum[mid]<x) low=mid+;
  21. else {
  22. return ;
  23. }
  24. }
  25. return ;
  26. }
  27.  
  28. int main()
  29. {
  30. int l,m,n,ll=;
  31. while(cin>>l>>m>>n)
  32. {
  33. ll++;
  34. for(int i=;i<l;i++)
  35. cin>>a[i];
  36. for(int j=;j<m;j++)
  37. cin>>b[j];
  38. for(int k=;k<n;k++)
  39. cin>>c[k];
  40.  
  41. pos=;
  42. for(int i=;i<l;i++)
  43. for(int j=;j<m;j++){
  44. sum[pos++]=a[i]+b[j];
  45. }
  46. sort(sum,sum+pos);
  47.  
  48. int xx;
  49. cin>>xx;
  50.  
  51. printf("Case %d:\n",ll);
  52.  
  53. for(int i=;i<=xx;i++){
  54. int x,flag=;
  55. cin>>x;
  56. for(int i=;i<n;i++){
  57. if(judge(x-c[i])){
  58. flag=;
  59. break;
  60. }
  61. }
  62.  
  63. if(flag)
  64. printf("YES\n");
  65. else printf("NO\n");
  66.  
  67. }
  68. }
  69. return ;
  70. }

G - Can you find it? 二分的更多相关文章

  1. codeforces 589G G. Hiring(树状数组+二分)

    题目链接: G. Hiring time limit per test 4 seconds memory limit per test 512 megabytes input standard inp ...

  2. G. Of Zorcs and Axes 二分 + 贪心 —— STL的用法

    http://codeforces.com/gym/101149/problem/G 一开始还以为要用二分图去做,但是复杂度也太高了,O(n * m)的话直接爆炸. 考虑贪心,考虑第i个东西优先选一个 ...

  3. Educational Codeforces Round 37 G. List Of Integers (二分,容斥定律,数论)

    G. List Of Integers time limit per test 5 seconds memory limit per test 256 megabytes input standard ...

  4. ACM-ICPC 2018 南京赛区网络预赛 G. Lpl and Energy-saving Lamps(二分+线段树区间最小)

    During tea-drinking, princess, amongst other things, asked why has such a good-natured and cute Drag ...

  5. 洛谷——P3939 数颜色(暴力vecotr+二分)

    P3939 数颜色 $vecotr$里二分就是好用,全是$STL$ 颜色数目比较少,可以对每一种颜色弄一个$vector$记录一下,查找$l,r$内颜色数为$x$的兔子数,直接在$G[x]$这个$ve ...

  6. POJ3189二分最大流(枚举下界,二分宽度,最大流判断可行性)

    题意:       有n头猪,m个猪圈,每个猪圈都有一定的容量(就是最多能装多少只猪),然后每只猪对每个猪圈的喜好度不同(就是所有猪圈在每个猪心中都有一个排名),然后要求所有的猪都进猪圈,但是要求所有 ...

  7. noip2016十连测round2

    A: Divisors 题意:给定 m 个不同的正整数 a 1 ,a 2 ,...,a m ,请对 0 到 m 每一个 k 计算,在区间 [1,n] 里有多少正整数 是 a 中恰好 k 个数的约数. ...

  8. POJ 2728 Desert King ★(01分数规划介绍 && 应用の最优比率生成树)

    [题意]每条路径有一个 cost 和 dist,求图中 sigma(cost) / sigma(dist) 最小的生成树. 标准的最优比率生成树,楼教主当年开场随手1YES然后把别人带错方向的题Orz ...

  9. POJ 1631 Bridging signals(LIS O(nlogn)算法)

    Bridging signals Description 'Oh no, they've done it again', cries the chief designer at the Waferla ...

随机推荐

  1. 图-搜索-DFS-37. 解数独

    2020-03-24 22:23:32 问题描述: 编写一个程序,通过已填充的空格来解决数独问题. 一个数独的解法需遵循如下规则: 数字 1-9 在每一行只能出现一次.数字 1-9 在每一列只能出现一 ...

  2. 一文上手TensorFlow2.0(一)

    目录: Tensorflow2.0 介绍 Tensorflow 常见基本概念 从1.x 到2.0 的变化 Tensorflow2.0 的架构 Tensorflow2.0 的安装(CPU和GPU) Te ...

  3. openssl与java(读取加密码的密钥)

    最近在研究java security方面的东西,java自带可以使用各种加密解密算法(rsa,dsa,des3,aes,md5...),但往往一些密钥是第三方给我们的,我们需要用java装载这些密钥然 ...

  4. Material Design 组件之NavigationView

    今天来看一下 NavigationView 的使用,NavigationView 是一个标准的导航菜单,其菜单内容由菜单资源文件来填充,NavigationView 一般和 DrawerLayout ...

  5. RecyclerView 的简单使用

    自从 Android 5.0 之后,google 推出了一个 RecyclerView 控件,他是 support-v7 包中的新组件,是一个强大的滑动组件,与经典的 ListView 相比,同样拥有 ...

  6. OpenWrite技术自媒体界的JVM一次编辑、随处发布

    原文 :https://mp.weixin.qq.com/s/KUtJ2dwhBRuJ2G_-PkQFEA 最懂你的科技自媒体管理平台 [实用小工具推荐]给科技或技术同学们推荐一款比较好用的工具,可以 ...

  7. 深入解读ES6系列(一)

    ECMAScript 6(ES6)简介 前言: 哈喽小伙伴们,爱说'废'话的Z又回来了,欢迎来到Super IT曾的博客时间,我说啦这个月要带的福利,说了更的博客肯定不能水你们,要一起进步学习嘛,今天 ...

  8. Js闭包练习2020031801

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...

  9. NKOJ4270 小奇挖矿2

    问题描述 [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿石交易市场,以便为飞船升级无限非概率引擎. [问题描述] 现在有m+1个星球,从左到右标号为0到m,小 ...

  10. Otb_000_ElementUI 的 Drawer组件无法上下滚动没有滚动条

    场景:当导航为侧边栏的时候,鼠标滚轮滑动的时候,以及移动端,均不可上下拖动,如果展开全部将影响操作. 解决办法: /*1.显示滚动条:当内容超出容器的时候,可以拖动:*/ .el-drawer__bo ...