hdu2141_Can you find it?
2015-07-23 08:42
357 查看
Can you find it?
Time Limit:3000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u
Submit Status
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
Sample Output
Time Limit:3000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u
Submit Status
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 <algorithm> #include <string.h> const int maxn=501; using namespace std; int a[maxn],b[maxn],c[maxn],s,tab[maxn*maxn]; bool bs(int cn,int key) { int low=0,high=cn-1,mid; while(low<=high) { mid=low+(high-low)/2; if(tab[mid]==key) return true; else if(tab[mid]>key) high=mid-1; else low=mid+1; } return false; } int main() { int l,m,n,cnt=0; while(scanf("%d%d%d",&l,&m,&n)!=EOF) { int x;int cn=0; for(int i=0;i<l;i++) scanf("%d",&a[i]); for(int j=0;j<m;j++) scanf("%d",&b[j]); for(int k=0;k<n;k++) scanf("%d",&c[k]); for(int i=0;i<l;i++) { for(int j=0;j<m;j++) { tab[cn++]=a[i]+b[j]; } } sort(tab,tab+cn); sort(c,c+n); scanf("%d",&s); printf("Case %d:\n",++cnt); for(int p=0;p<s;p++) { bool pt=false; scanf("%d",&x); for(int i=0;i<n;i++) { if(bs(cn,x-c[i])) { pt=true; printf("YES\n"); break; } } if(!pt)printf("NO\n"); } memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); memset(tab,0,sizeof(tab)); } return 0; }
相关文章推荐
- iOS 开发第一步 C语言基础之递归
- [Leetcode 34, Medium] Search for a Range
- 资源网站
- LeetCode OJ 之 Search a 2D Matrix II (二维矩阵查找)
- 结构型模式-装饰模式
- 7月19日Docker&Kubernetes技术沙龙总结 - DockOne.io
- OC中字符串的提取与替换-四种不同方法实现
- coj1022_菜鸟与大牛
- Python的Lambda函数与排序
- COJ 0578 4019二分图判定
- 【暴力搜索】分数分解
- swap
- 置换群好题
- HDU 1707 简单模拟 Spring-outing Decision
- c# 读取文件流
- 使用genstring和NSLocalizedString实现App文本的本地化
- Hibernate 的延迟加载(懒加载)简介1
- 如何学习源码----转自知乎
- 使用genstring和NSLocalizedString实现App文本的本地化
- thrift的使用介绍