国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Hdu Can you find it?(二分答案)

2019-11-14 11:16:59
字體:
來源:轉載
供稿:網友

Can you find it? Time Limit: 10000/3000 MS (java/Others) Memory Limit: 32768/10000 K (Java/Others) 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 3 1 2 3 1 2 3 1 2 3 3 1 4 10 Sample Output Case 1: NO YES NO Author wangye Source HDU 2007-11 Programming Contest

/*二分答案.比較巧妙.先將兩個數組合并搞成一個n^2大的數組.然后二分的話復雜度就有一個log.二分和合并后的數組即對n^2取log.然后復雜度就大大降低了.*/#include<iostream>#include<algorithm>#include<cstdio>#define MAXN 501#define LL long longusing namespace std;LL s[MAXN*MAXN],a[MAXN],b[MAXN],c[MAXN],n1,n2,n3,n,m;LL read(){ LL x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9') x=x*10+ch-48,ch=getchar(); return x*f;}bool erfen(int l,int r,int i,int x){ int mid; while(l<=r) { mid=(l+r)>>1; if(s[mid]+c[i]==x) return true; if(s[mid]+c[i]>x) r=mid-1; else l=mid+1; } return false;}void slove(){ int x; bool flag; while(m--) { flag=false;x=read(); for(int i=1;i<=n3;i++) if(erfen(1,n,i,x)){flag=true;printf("YES/n");break;} if(!flag) printf("NO/n"); } return ;}int main(){ int t=0; while(~scanf("%d%d%d",&n1,&n2,&n3)) { printf("Case %d:/n",++t);n=0; for(int i=1;i<=n1;i++) a[i]=read(); for(int i=1;i<=n2;i++) b[i]=read(); for(int i=1;i<=n3;i++) c[i]=read(); for(int i=1;i<=n1;i++) for(int j=1;j<=n2;j++) s[++n]=a[i]+b[j]; sort(s+1,s+n+1); m=read();slove(); } return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 黎平县| 洛隆县| 大化| 贵港市| 读书| 棋牌| 丰镇市| 博白县| 咸阳市| 库车县| 凉山| 阿城市| 孟津县| 乐清市| 玉树县| 永平县| 神农架林区| 牟定县| 阳信县| 苏州市| 阜城县| 修水县| 佛坪县| 阿城市| 北安市| 柘荣县| 璧山县| 华容县| 南京市| 通河县| 柞水县| 郴州市| 曲周县| 吐鲁番市| 荆州市| 沂源县| 灵川县| 蒲城县| 岚皋县| 岚皋县| 黄冈市|