hdu2141Can you find it?(二分查找)
来源:互联网 发布:支付宝怎么登陆淘宝 编辑:程序博客网 时间:2024/05/16 12:37
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#include<stdio.h>#include<iostream>#include<algorithm>using namespace std;#define N 4000000int len[4],n;__int64 ss[N],num[4][1005],x;int cmp(int a,int b){return a<b;}void dfs(__int64 sum,int v){ if(v==2) { ss[n++]=sum; return; } for(int i=0;i<len[v];i++) dfs(sum+num[v][i],v+1);}int two(__int64 sum){ int l,mid,r; l=0;r=n-1; while(l<=r) { mid=(l+r)/2; if(ss[mid]==sum) break; if(ss[mid]<sum) l=mid+1; if(ss[mid]>sum) r=mid-1; } if(l<=r)return 1; return 0;}int main(){ int s,t=0,flog; while(scanf("%d%d%d",&len[0],&len[1],&len[2])>0) { n=0; for(int i=0;i<3;i++) for(int j=0;j<len[i];j++) scanf("%I64d",&num[i][j]); dfs(0,0); sort(ss,ss+n,cmp); scanf("%d",&s); printf("Case %d:\n",++t); while(s--) { scanf("%I64d",&x); flog=0; for(int i=0;i<len[2];i++) if(two(x-num[2][i])) { flog=1;break; } printf("%s\n",flog?"YES":"NO"); } }}
- hdu2141Can you find it?(二分查找)
- hdu2141Can you find it?
- hdu2141Can you find it?
- HDU2141Can you find it?
- hdu2141Can you find it?
- Can you find it? hdu2141 二分查找
- HDOJ2141Can you find it?【二分查找】
- Can you find it? (HDU_2141) 二分查找
- [HDU](2141)Can you find it? ---二分查找(查找)
- hdu 2141 Can you find it? 二分查找
- HDU 1241 Can you find it? (二分查找)
- hdu 2141 Can you find it? 二分查找 + 数组合并
- Can you find it?+合并字串+二分查找
- hdu 2141——Can you find it(二分查找)
- hdu 2141 Can you find it? (二分查找)
- [ACM] hdu 2141 Can you find it? (二分查找)
- HDU 2141Can you find it(二分查找)
- 二分查找:hdu 2141 Can you find it?
- 正则表达式基础
- Flex 设置WMODE 后滚轮失效的解决方法
- 虚拟机与主机共享以及arm-linux-gcc3.3.2安装过程
- Linux设备模型(热插拔、mdev 与 firmware)
- EditText输入文字带下划线的效果
- hdu2141Can you find it?(二分查找)
- C#版数据包抓取过滤监控器
- 软件“版本”大全
- python 文件操作
- 甩掉学生气,做成熟的自己
- 比赛_ny_871(排序).java
- 完数 1406
- 超值广州PHP培训课程尽在广州传智播客
- 学.NET技术去哪里最好?