Can you find it?
来源:互联网 发布:高仿球鞋的淘宝店 编辑:程序博客网 时间:2024/05/01 20:48
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
一开始TLE因为是三个for循环在一起,后来将两个for循环分开就没TLE了
#include<cstdio>#include<iostream>#include<algorithm>#include<cstdlib>int n,m,l,t,f,tmp,q;using namespace std;int a[1000],b[1000],c[1000],d[2555555];int main(){int cnt=0; while(~scanf("%d%d%d",&l,&n,&m)) {f=0; for(int i=0;i<l;i++) scanf("%d",&a[i]); for(int i=0;i<n;i++) scanf("%d",&b[i]); for(int i=0;i<m;i++) scanf("%d",&c[i]); int y=0; for(int j=0;j<l;j++) for(int k=0;k<n;k++) d[y++]=a[j]+b[k]; sort(d,d+y); scanf("%d",&t); printf("Case %d:\n",++cnt); while(t--) {scanf("%d",&tmp); for(int i=0;i<m;i++) {q=tmp-c[i]; int low=0; int high=y-1; int mid=(y-1)/2; while(low<high) { if(d[mid]==q) {f=1; break;} if(d[mid]<q) low=mid+1; if(d[mid]>q) high=mid-1; mid=(high+low)/2; } if(d[low]==q || d[high]==q) f=1; if(f) break;} if(f==1) printf("YES\n"); else printf("NO\n"); f=0; }} return 0;}
- can you find it?
- Can you find it?
- Can you find it?
- Can you find it?
- can you find it?
- Can you find it?
- can you find it?
- Can you find it?
- Can you find it?
- Can you find it?
- Can you find it?
- can you find it?
- Can you find it?
- Can you find it?
- Can you find it?
- HDU Can you find it?
- HDU2141 Can you find it?
- Can you find it?---二分
- 模式识别:k-均值聚类算法的研究与实现
- ios UITableView separatorColor 默认颜色
- java处理图片--图片的缩放,旋转和马赛克化
- Android FragmentStatePagerAdapter.notifyDataSetChanged()刷新数据的问题
- JQ checkbox 全选 反选获取值
- Can you find it?
- 可变参数列表及printf函数的实现
- 有一个一维数组,里面放入十个学生的成绩,写一个函数,求出平均分,最高分和最低分(用全局变量的方法)
- 渣渣ACM日记——1009-FatMouse' Trade (HDOJ)
- file.toURI().toURL()
- Shell
- 获取某个网页的源代码显示在手机界面上
- 认识自己——人的野心和目标
- Mybatis学习(六)mybatis与hibernate区别与应用场景