首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >【HDU】2141 - Can you find it?(STL)

【HDU】2141 - Can you find it?(STL)

作者头像
FishWang
发布2025-08-27 09:12:11
发布2025-08-27 09:12:11
5500
代码可运行
举报
运行总次数:0
代码可运行

点击打开题目

Can you find it?

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

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

代码语言:javascript
代码运行次数:0
运行
复制
   3 3 3
1 2 3
1 2 3
1 2 3
3
1
4
10

Sample Output

代码语言:javascript
代码运行次数:0
运行
复制
   Case 1:
NO
YES
NO

Author

wangye

Source

HDU 2007-11 Programming Contest

需要合并数组(昨天新数组少开100倍而无限 MLE 的事就不要再提了 = = ),然后从 c 中取数在新数组二分查找(lower_bound () )查找就行。

代码如下:

代码语言:javascript
代码运行次数:0
运行
复制
#include <cstdio>
#include <map> 
#include <algorithm>
using namespace std;
int main()
{
	int la,lb,lc;
	int a[511],c[511];
	int num[250011];
	int ant;
	int Case = 1;
	while (~scanf ("%d %d %d",&la,&lb,&lc))
	{
		ant = 0;
		for (int i = 1 ; i <= la ; i++)
			scanf ("%d",&a[i]);
		for (int i = 1 ; i <= lb ; i++)
		{
			int t;
			scanf ("%d",&t);
			for (int j = 1 ; j <= la ; j++)
				num[ant++] = a[j] + t;
		}
		for (int i = 1 ; i <= lc ; i++)
			scanf ("%d",&c[i]);
		sort (num,num+ant);
		ant = unique(num,num+ant) - num;		//去重 
		printf ("Case %d:\n",Case++);
		int Q;
		int m;
		scanf ("%d",&m);
		while (m--)
		{
			scanf ("%d",&Q);
			bool ans = false;
			for (int i = 1 ; i <= lc ; i++)
			{
				int pos = lower_bound (num , num + ant , Q - c[i]) - num;
				if (num[pos] + c[i] == Q)
				{
					ans = true;
					break;
				}
			}
			if (ans)
				printf ("YES\n");
			else
				printf ("NO\n");
		}
	}
	return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2025-08-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Can you find it?
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档