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 ...
随机推荐
- crtmp Server 开启rtsp服务功能
Crtmp Server 包含了rtsp 服务功能,如果需要一个简单轻量的rtsp服务,Crtmp Server会是不错的选择. 默认情况下,rtsp功能是关闭的,需要在配置文件中打开.window环 ...
- Spark技术内幕: Task向Executor提交的源代码解析
在上文<Spark技术内幕:Stage划分及提交源代码分析>中,我们分析了Stage的生成和提交.可是Stage的提交,仅仅是DAGScheduler完毕了对DAG的划分,生成了一个计算拓 ...
- AOSP ON MAKO(在NEXUS 4上刷ANDROID 4.4 源代码包-下载/配置/编译/刷机)
AOSP ON MAKO(在NEXUS 4上刷ANDROID 4.4 源代码包-下载/配置/编译/刷机) 特别感谢google官方文档及AOSP源代码开放 參考链接: https://source.a ...
- POJ 3335 Rotating Scoreboard(半平面交 多边形是否有核 模板)
题目链接:http://poj.org/problem? id=3335 Description This year, ACM/ICPC World finals will be held in a ...
- kubernetes里的各种port解惑
系列目录 在编排kubernetes时,Deployment的Pod项有containerPort,Service文件里的port,targetPort, nodePort,这些pod概念有些时候可能 ...
- 生产追溯系统-Wifi+传感器,实现计数器以及监控机器是否停止
物联网听上去是一个高大上的词儿,还有什么大数据.云.智能制造等等,今天我也往这方面稍微靠一靠,这篇文章主要介绍的是通过 wifi 模块与传感器组合,实现感应计数器,应用场景主要如下: 1.统计 SMT ...
- 升级svn 到1.7
sudo yum update sudo yum groupinstall "Development tools" sudo yum groupinstall "Addi ...
- python中的and和or(转载)
python中的and和or 4.6. and 和 or 的特殊性质在Python 中,and 和 or 执行布尔逻辑演算,如你所期待的一样,但是它们并不返回布尔值:而是,返回它们实际进行比较的值之一 ...
- 【MatConvNet】配置GPU
参照大神的方法:http://www.th7.cn/system/win/201603/155182.shtml 第一步:需要安装cuda.VS2013:cuda默认路径,注意cuda版本和GPU要匹 ...
- asp.net mvc4 修改密码界面
1.效果 说明:1.界面不太美观 这里面主要是包括 利用jQuery 插件validate验证form字段,jQuery提交form表单的方式 1.HTML代码 <!DOCTYPE html&g ...