hdu 2141 Can you find it?(二分)
来源:互联网 发布:asp信息录入系统源码 编辑:程序博客网 时间:2024/05/01 11:30
Can you find it?
Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/Others)Total Submission(s): 24883 Accepted Submission(s): 6302
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
Author
wangye
Source
HDU 2007-11 Programming Contest
tips:利用unique进行查重,一定要先排序再进行查重。
三个数组两个数组之间二分的处理方式。
#include<iostream> #include<algorithm> using namespace std; __int64 a[503]; __int64 b[503]; __int64 c[503]; int len; __int64 sum[300001]; int _case; int la,lb,lc; int bin(__int64 x) { int left=0; int right=len-1; while(left<=right) { int mid=(left+right)/2; if(x>sum[mid])left=mid+1; else if(x==sum[mid])return 1; else right=mid-1; } return 0; } int main() { while(cin>>la>>lb>>lc) { _case++; cout<<"Case "<<_case<<":"<<endl; len=0; for(int i=0;i<la;i++) cin>>a[i]; for(int j=0;j<lb;j++) cin>>b[j]; for(int k=0;k<lc;k++) cin>>c[k]; sort(c,c+lc);for(int i=0;i<la;i++)for(int j=0;j<lb;j++){sum[len++]=a[i]+b[j];}sort(sum,sum+len);//使用unique函数进行去重,一定要先排序再去重 len=unique(sum,sum+len)-sum; int x; cin>>x; while(x--) { int flag=0; __int64 ans; cin>>ans; if(ans<c[0]+sum[0]||ans>c[lc-1]+sum[len-1]){cout<<"NO"<<endl;continue; } for(int i=0;i<lc;i++) { if(bin(ans-c[i])) { flag=1; break; } } if(flag)cout<<"YES"<<endl; else cout<<"NO"<<endl; } } return 0; }
0 0
- hdu 2141 Can you find it? 二分
- HDU 2141 Can you find it?(二分)
- hdu 2141 Can you find it? 二分
- HDU 2141 Can you find it?【二分】
- 【HDU 2141】【二分】 Can you find it?
- HDU 2141 Can you find it? (二分)
- HDU-2141-Can you find it?【二分】
- HDU 2141 Can you find it?二分
- hdu 2141 Can you find it?(二分)
- hdu 2141 Can you find it?(二分)
- hdu 2141 Can you find it?(二分)
- HDU 2141 Can you find it? <二分>
- Hdu Can you find it?(二分答案)
- hdu 2141 Can you find it? 二分查找
- hdu 2141 Can you find it? 二分查找 + 数组合并
- hdu 2141——Can you find it(二分查找)
- HDOJ/HDU 2141 Can you find it? 二分搜索优化
- hdu 2141 Can you find it? (二分查找)
- Android RecyclerView使用完全解析-体验艺术般的控件
- Android 抽奖 GridView 只显示周围一圈的item 纯算法实现
- 关于滚动条的几个参数
- C/C++字符串,字符数组,字符指针及其相互静态拷贝与追加的安全问题解决方案(2)
- 数据结构之栈(C语言实现)
- hdu 2141 Can you find it?(二分)
- Apple公司Darwin流式服务器源代码分析(一)
- DM8168 DVRRDK软件框架研究
- Maven手动添加本地jar包
- HDU 2094 产生冠军(map)
- 全栈工程师之路(二)—— JavaScript(网页前端脚本语言)
- 小波变换基础
- 【OpenCV】访问Mat中每个像素的值(新)
- 利用SlidingMenu框架做侧滑菜单