博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 2141 Can you find it?
阅读量:5280 次
发布时间:2019-06-14

本文共 3315 字,大约阅读时间需要 11 分钟。

Can you find it?

Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/10000 K (Java/Others)

Total Submission(s): 3758    Accepted Submission(s): 935

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
 
 
这题是题好二分,要把两个数组合拼成一个。一个小地方错(代码里注明),让我找半天都找不到那里错。晕呀。。。现在还要搞清楚while(l < (=)r)的等号有与没的区别还有l = mid + 1和r = mid (- 1)要不要1。
还有如果数组从1...n和0...n-1的区别。要把这个弄清楚。
 
 
View Code
1 #include 
2 #include
3 #define maxn 505 4 5 int a[maxn], b[maxn], c[maxn], ab[maxn*maxn]; 6 int l, n, m; 7 8 int Cmp(const void *a, const void *b) 9 {
10 return *(int *)a - *(int *)b; 11 } 12 13 int F(int n, int k) 14 {
15 int l, r, mid; 16 l = 0; 17 r = k - 1;//当时就是这里没多加个变量k,而直接l * m,搞得一直WA 18 while (l < r) 19 {
20 mid = (l + r) / 2; 21 if (ab[mid] == n) 22 {
23 return 1; 24 } 25 if (ab[mid] > n) 26 {
27 r = mid; 28 } 29 else 30 {
31 l = mid + 1; 32 } 33 } 34 return 0; 35 } 36 37 38 int main() 39 {
40 int i, j, k, times = 1, flag, s, x; 41 42 while (scanf("%d%d%d", &l, &m, &n) != EOF) 43 {
44 for (i = 0; i < l;scanf("%d", &a[i++])); 45 for (j = 0; j < m;scanf("%d", &b[j++])); 46 for (k = 0; k < n;scanf("%d", &c[k++])); 47 48 49 k = 0; 50 for (i = 0; i < l; i++) 51 {
52 for (j = 0; j < m; j++) 53 {
54 ab[k++] = a[i] + b[j]; 55 } 56 } 57 qsort(ab, k, sizeof(ab[0]), Cmp); 58 59 printf("Case %d:\n", times++); 60 scanf("%d", &s); 61 62 while (s--) 63 {
64 scanf("%d", &x); 65 flag = 1; 66 for (i = 0; i < n; i++) 67 {
68 if (F(x - c[i], k) == 1) 69 {
70 flag = 0; 71 break; 72 } 73 } 74 if (flag == 0) 75 {
76 puts("YES"); 77 } 78 else 79 {
80 puts("NO"); 81 } 82 } 83 } 84 85 return 0; 86 }
 

转载于:https://www.cnblogs.com/qiufeihai/archive/2012/01/26/2329613.html

你可能感兴趣的文章
51nod1076 (边双连通)
查看>>
Linux pipe函数
查看>>
Zerver是一个C#开发的Nginx+PHP+Mysql+memcached+redis绿色集成开发环境
查看>>
程序的静态链接,动态链接和装载 (补充)
查看>>
关于本博客说明
查看>>
[Kaggle] Sentiment Analysis on Movie Reviews
查看>>
价值观
查看>>
mongodb命令----批量更改文档字段名
查看>>
国外常见互联网盈利创新模式
查看>>
android:scaleType属性
查看>>
shell脚本
查看>>
Upload Image to .NET Core 2.1 API
查看>>
【雷电】源代码分析(二)-- 进入游戏攻击
查看>>
Linux中防火墙centos
查看>>
[JS]递归对象或数组
查看>>
linux sed命令
查看>>
程序存储问题
查看>>
优雅地书写回调——Promise
查看>>
PHP的配置
查看>>
Struts框架----进度1
查看>>