链接:http://acm.hdu.edu.cn/showproblem.php?pid=2141

Can you find it?

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

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
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
这题写的不爽,不写题解了,看代码吧
 #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm> using namespace std; long long sum[];
int str1[],str2[],str3[]; int Table(int l,int n,int m)
{ int cas=;
for(int i=; i<l ;i++)
{ for(int j=; j<n; j++)
{ sum[cas++]=str1[i]+str2[j];
}
}
return cas;
} bool BSearch(long long sum[],int k,int cas)
{ int left=,right=cas-;
while(left<=right)
{ int mid=(left+right)>>;
if(sum[mid] == k) return true;
else if(k < sum[mid]) right=mid-;
else left = mid+;
}
return false;
} int main()
{ int l,m,n,i,j;
int ss=;
while(scanf("%d%d%d",&l,&n,&m)!=EOF)
{ memset(str1,,sizeof(str1));
memset(str2,,sizeof(str2));
memset(str3,,sizeof(str3)); for(i=; i<l; i++)
scanf("%d",&str1[i]);
for(j=; j<n; j++)
scanf("%d",&str2[j]);
for(i=; i<m; i++)
scanf("%d",&str3[i]);
int k,tmp;
scanf("%d",&k);
int cas=Table(l,n,m);
sort(sum,sum+cas);
printf("Case %d:\n",ss++);
while(k--)
{
scanf("%d",&tmp);
for(i=; i<m; i++)
{ if(BSearch(sum,tmp-str3[i],cas))
{ printf("YES\n");
break;
}
}
if(i>=m)printf("NO\n");
} }
return ;
}

hdu 2141 (二分)的更多相关文章

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

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

  2. hdu 4024 二分

    转自:http://www.cnblogs.com/kuangbin/archive/2012/08/23/2653003.html   一种是直接根据公式计算的,另外一种是二分算出来的.两种方法速度 ...

  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?(二分查找变例)

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

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

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

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

随机推荐

  1. HID USB设备开发技术【转】

    本文转载自: 1.高速USB和USB2.0有区别吗?     高速USB和USB2.0是有区别的,区别在于USB2.0是一种规范,而"高速USB"仅指在USB2.0规范中数据传输率 ...

  2. Table Properties [AX 2012]

    Table Properties [AX 2012] 1 out of 2 rated this helpful - Rate this topic Updated: July 20, 2012 Ap ...

  3. Docker Centos安装Mysql5.6

    之前一篇随笔<Docker Centos安装Openssh> 写的是如何在基础的centos镜像中搭建ssh服务,在此基础上再搭建其他服务.本文继续介绍在centos_ssh基础上搭建my ...

  4. Codeforces 745C:Hongcow Builds A Nation(并查集)

    http://codeforces.com/problemset/problem/744/A 题意:在一个图里面有n个点m条边,还有k个点是受限制的,即不能从一个受限制的点走到另外一个受限制的点(有路 ...

  5. ReactDom.render和React.render的区别

    这个是react最新版api,也就是0.14版本做出的改变.主要是为了使React能在更多的不同环境下更快.更容易构建.于是把react分成了react和react-dom两个部分.这样就为web版的 ...

  6. [Unity3D]MonoBehaviour函数介绍

    原文地址: http://www.cocos2dev.com/?p=486 Unity中的脚本都是继承自MonoBehaviour. 一.基础函数: 创建脚本就默认的update.start方法:(这 ...

  7. 多校3- RGCDQ 分类: 比赛 HDU 2015-07-31 10:50 2人阅读 评论(0) 收藏

    RGCDQ Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practic ...

  8. K - Work 分类: 比赛 2015-07-29 19:13 3人阅读 评论(0) 收藏

    K - Work Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  9. CurrentHashMap的实现原理

    转载:http://wiki.jikexueyuan.com/project/java-collection/concurrenthashmap.html 概述 我们在之前的博文中了解到关于 Hash ...

  10. ubuntu下查看cpu信息

    查看CPU信息cat /proc/cpuinfo 几个cpu more /proc/cpuinfo |grep "physical id"|uniq|wc -l 每个cpu是几核( ...