码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 2141 Can you find it?

时间:2015-07-30 19:26:23      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:

          Can you find it?

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
 1 #include<cstdio>
 2 #include<algorithm>
 3 using namespace std;
 4 
 5 int p[3][505];
 6 long long temp[250010];
 7 int s[1005];
 8 
 9 int main()
10 {
11     //freopen("in.txt","r",stdin);
12     int a,b,c,i,j,k,n;
13     int m=0;
14     while(scanf("%d%d%d",&a,&b,&c)!=EOF)
15     {
16         printf("Case %d:\n",++m); 
17         for(i=0;i<a;i++)
18         scanf("%d",&p[0][i]);
19         for(i=0;i<b;i++)
20         scanf("%d",&p[1][i]);
21         for(i=0;i<c;i++)
22         scanf("%d",&p[2][i]);
23         scanf("%d",&n);
24         for(i=0;i<n;i++)
25         scanf("%d",&s[i]);
26         int k=-1;
27         for(i=0;i<b;i++)
28         for(j=0;j<c;j++)
29         temp[++k]=p[1][i]+p[2][j];
30         sort(temp,temp+k);
31         for(j=0;j<n;j++)
32         {
33             int target;
34             int ans;
35             for(i=0;i<a;i++)
36             {
37                 target=s[j]-p[0][i]; 
38                 int ans=lower_bound(temp,temp+k,target)-temp;
39                 if(temp[ans]==target) 
40                 break;
41             }
42             if(i!=a)
43             printf("YES\n");
44             else
45             printf("NO\n");    
46         }
47     } 
48     
49 }

 

 

HDU 2141 Can you find it?

标签:

原文地址:http://www.cnblogs.com/homura/p/4690231.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!