博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU - 2141 : Can you find it?
阅读量:4925 次
发布时间:2019-06-11

本文共 1506 字,大约阅读时间需要 5 分钟。

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

3 3 31 2 31 2 31 2 331410

Sample Output

Case 1:NOYESNO 给三组整数,在下面每给一个整数,判断从三组数各取一个相加与此整数是否可以相等。 直接暴力复杂度为O(N^3),不可行。可以将前两组枚举,复杂度为O(N^2),再排序,对于每一个目标数,枚举第三组数,二分查找前两组的和即可。 源代码: #include
#include
#include
using namespace std; int a[505],b[505],c[505],d[250005]; int main() { int L,M,N,S,s=1,x,y,z,flag; while(cin>>L>>M>>N) { y=0; flag=0; cout<<"Case "<
<<":"<
>a[i]; for(int i=0;i
>b[i]; for(int i=0;i
>c[i]; for(int j=0;j
>S; for(int i=0;i
>x; flag=0; for(int j=0;j

转载于:https://www.cnblogs.com/xibeiw/p/7239937.html

你可能感兴趣的文章
html5--6-52 动画效果-过渡
查看>>
调查表与调查结果分析
查看>>
Windows系统下安装MySQL详细教程(命令安装法)
查看>>
PHP实用小程序(六)
查看>>
PDFsharp Samples
查看>>
django-cms 代码研究(八)app hooks
查看>>
peewee Model.get的复杂查询
查看>>
IE浏览器兼容性设置的一些问题
查看>>
SQL Server复制入门(二)----复制的几种模式
查看>>
javascript 简单认识
查看>>
tomcat 系统架构与设计模式 第二部分 设计模式 转
查看>>
scanf中的%[^\n]%*c格式
查看>>
启动Eclipse报Initializing Java Tooling错误解决方法
查看>>
用jquery来实现类似“网易新闻”横向标题滑动的移动端页面
查看>>
(原)基于物品的协同过滤ItemCF的mapreduce实现
查看>>
CSS可以和不可以继承的属性
查看>>
eclipse每次当我按ctrl+鼠标点击代码,自动关闭,产生原因及解决办法!!
查看>>
hbase
查看>>
用PHP将Unicode 转化为UTF-8
查看>>
HDOJ1002 A+B Problem II
查看>>