HDOJ--2141 Can you find it?(包含题意)
来源:互联网 发布:编程的双引号怎么打 编辑:程序博客网 时间:2024/05/16 12:43
Can you find it?
Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/Others)Total Submission(s): 17547 Accepted Submission(s): 4437
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
3 3 31 2 31 2 31 2 331410
Sample Output
Case 1:NOYESNO题意:首先输入l,m,n,然后第一行输入l个整数,第二行输入m个整数,第三行输入n个整数。最终就是看你所给的数据中有没有满足第一行的一个数+第二行的一个数+第三行的一个数相等的结果,有的话就是"YES",没有就是NO.思路:主要就是利用二分法来进行时间的缩短免得超时。祥见代码。错误:总之犯了两个错误,导致一道题做了一下午。1、就是没有把top初始化。2、输出个事不对,没有加“:“超坑人,一个冒号导致了无数次的wa.ac代码:#include<stdio.h>#include<algorithm>using namespace std;int a[550],b[550],c[550],s[550*550];int part(int l,int r,int path){ while(l<=r){ int mid=(l+r)/2; if(s[mid]<path) l=mid+1; else if(s[mid]>path) r=mid-1; else return 1; } return 0;}int main(){ int l,m,n,i,j,k,top,count=0,flag=0; while(scanf("%d%d%d",&l,&n,&m)!=EOF){ top=-1; for(i=0;i<l;i++) scanf("%d",&a[i]); for(j=0;j<m;j++) scanf("%d",&b[j]); for(k=0;k<n;k++) scanf("%d",&c[k]); for(i=0;i<l;i++) for(j=0;j<m;j++) s[++top]=a[i]+b[j]; sort(s,s+top+1); int t; scanf("%d",&t); printf("Case %d:\n",++count); while(t--){ int x; flag=0; scanf("%d",&x); for(i=0;i<n;i++){ int y=x-c[i]; if(part(0,top,y)){ flag=1; break; } } if(flag) printf("YES\n"); else printf("NO\n"); } }}
0 0
- HDOJ--2141 Can you find it?(包含题意)
- HDU/HDOJ 2141 Can you find it?
- hdoj 2141 Can you find it?
- hdoj 2141 Can you find it? 【二分法】
- hdoj-2141 Can you find it?【二分】
- hdoj 2141 can you find it ?
- HDOJ 2141 Can you find it?
- hdoj-2141-Can you find it?
- HDOJ 2141 Can you find it?
- HDOJ-2141 Can you find it?
- HDOJ 2141 Can you find it?
- HDOJ 2141 Can you find it?
- HDOJ 2141 Can you find it?
- HDOJ 题目2141 Can you find it?(二分搜索)
- HDOJ 2141 Can you find it?(二分)
- HDOJ/HDU 2141 Can you find it? 二分搜索优化
- HDOJ Can you find it? 2141(二分搜索)
- HDOJ 2141 Can you find it?(二分查找,binary_search())
- android图片文件的路径地址与Uri的相互转换
- UIButton
- 创建文件有个问号
- iBatis开发详解(9)-----------查询复杂集合
- iOS-代理委托的使用
- HDOJ--2141 Can you find it?(包含题意)
- 主子报表多数据源的处理
- 将mp3文件数据转换成.h的头文件的音频数据
- 在applet(java plugin)中与javascript通信
- iBatis开发详解(10)---------------操作DDL和映射继承
- nginx+tomcat集群
- 内存管理的基本问题
- org.apache.jasper.JasperException: Unable to compile class for JSP:
- C++如何生成自己的静态库(lib)文件