hdu-2141
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): 7286Problem DescriptionGive 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 Input3 3 31 2 31 2 31 2 331410Sample OutputCase 1:NOYESNO
题意:给出三个数列ABC,从ABC各取一个整数求是否能够等于X,是则输出YES,否NO。
三组500直接查找会超时
可将A+B+C=X转换为A+B=X-C
之后即可将等式两边看做两个整体进行二分查找。
AC代码:
- #include<bits/stdc++.h>
- using namespace std;
- int a[],b[],c[];
- int num[];
- int bin(int q[],int x,int y){
- int left=,right=x,mid;
- while(left<=right){
- mid=(left+right)/;
- if(q[mid]==y)
- return ;
- if(q[mid]>y)
- right=mid-;
- else
- left=mid+;
- }
- return ;
- }
- int main(){
- int l,n,m,s,ans=;
- while(cin>>l>>n>>m){
- ans++;
- for(int i=;i<l;i++){
- cin>>a[i];
- }
- for(int i=;i<n;i++){
- cin>>b[i];
- }
- for(int i=;i<m;i++){
- cin>>c[i];
- }
- cin>>s;
- int x,cnt=;
- for(int i=;i<l;i++){
- for(int j=;j<n;j++){
- num[cnt++]=a[i]+b[j];
- }
- }
- sort(num,num+cnt);
- printf("Case %d:\n",ans);
- while(s--){
- cin>>x;
- int flag=;
- for(int i=;i<m;i++){
- int temp=x-c[i];
- if(bin(num,cnt-,temp)){
- cout<<"YES"<<endl;
- flag=;
- break;
- }
- }
- if(!flag)
- cout<<"NO"<<endl;
- }
- }
- return ;
- }
hdu-2141的更多相关文章
- hdu 2141 (二分)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2141 Can you find it? Time Limit: 10000/3000 MS (Java/O ...
- hdu 2141 Can you find it?
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2141 Can you find it? Description Give you three sequ ...
- hdu 2141 Can you find it?(二分查找)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2141 题目大意:查找是否又满足条件的x值. 这里简单介绍一个小算法,二分查找. /* x^2+6*x- ...
- HDU 2141 Can you find it? (二分)
题目链接: Can you find it? Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/ ...
- hdu 2141:Can you find it?(数据结构,二分查找)
Can you find it? Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/Others ...
- hdu 2141 Can you find it? (二分法)
Can you find it? Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/Others ...
- Can you find it?(hdu 2141 二分查找)
Can you find it? Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/Others ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 基于RFS(robot framework selenium)框架模拟POST/GET请求执行自动化接口测试
打开RIDE添加测试用例 如: Settings Library Collections Library RequestsLibrary Test Cases ...
- C++入门一
C++ 项目结构 Resource Files: 项目引用的位图文件,图标,窗口,光标等.比如,你的程序要生成一个exe文件,而文件的图标是你自定义的图标,那就要在这个工程里面添加Icon资源,添加一 ...
- upstart man
man upstart nit(8) init(8) NAME init - Upstart process management daemon SYNOPSIS init [OPTION]... D ...
- find and xargs
调整搜索深度 -mandepth 搜索当前目录,而不进入子目录: find . -maxdepth 0 -name "debug*" Linux中find常见用法示例 ·find ...
- kubernetes之常见故障排除(一)
系列目录 由由种种原因,在安装或者使用kubernetes的过程中,可能会遇到各种各样的问题.本篇按照官网的介绍罗列出一些常见的故障,以帮助快速解决一些常见的错误. 安装赛程中出现ebtables o ...
- Apache Server与多个独立Tomcat集成
取经自http://www.ramkitech.com/2012/03/virtual-host-apache-httpd-server-tomcat.html 继续干Tomcat和Apache Se ...
- SegmentFault 巨献 1024 程序猿游戏「红岸的呼唤」第二天任务攻略
眼看实验室就要关门了.走之前写一下解题过程(事实上大家都等着第三题出来吧大概-=). 高速传送门:http://segmentfault.com/game/2 那么接昨天的博客,今天的题目是这种: 完 ...
- 继承的文本框控件怎么响应EN_CHANGE等消息
继承的文本框控件如何响应EN_CHANGE等消息?我从CEdit继承了一个CMyEdit类,想在这个类里填写它的一些消息.我在消息映射表里写的是MESSAGE_HANDLER(EN_CHANGE, O ...
- mysql 中的增改查删(CRUD)
增改查删可以用CURD来表示 增加:create 修改:update 查找:read 删除:delete 增加create : insert +表名+values+(信息): in ...
- 我读过的最好的epoll讲解
首先我们来定义流的概念,一个流可以是文件,socket,pipe等等可以进行I/O操作的内核对象. 不管是文件,还是套接字,还是管道,我们都可以把他们看作流. 之后我们来讨论I ...