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

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

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

2019-11-14 11:13:36
字體:
來源:轉載
供稿:網友

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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 栾城县| 兴义市| 额济纳旗| 民乐县| 扬中市| 达孜县| 霞浦县| 陇南市| 邛崃市| 恭城| 松溪县| 隆子县| 杭锦后旗| 揭西县| 四子王旗| 方城县| 客服| 沈阳市| 浦江县| 永春县| 常山县| 施甸县| 晴隆县| 偏关县| 惠东县| 张家口市| 永康市| 六盘水市| 尉犁县| 措美县| 乐亭县| 新郑市| 固安县| 交城县| 铜陵市| 惠东县| 买车| 阳信县| 竹北市| 竹溪县| 西青区|