标签:des style blog http io color os ar for
分析:
用10^4打表 用10^2枚举
我的lower_bound一直挂 只能手写二分 不过还好
代码:
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 7 const int maxn = 505; 8 int a[maxn], b[maxn], c[maxn], d[maxn * maxn]; 9 10 int cnt; 11 bool check(int num) { 12 int low = 0; int high = cnt - 1; 13 while(low <= high) { 14 int mid = ( low + high) >> 1; 15 if(d[mid] >= num) { 16 high = mid - 1; 17 } else { 18 low = mid + 1; 19 } 20 } 21 if(d[high + 1] == num) return true; 22 return false; 23 } 24 25 int main() { 26 int l, n, m; 27 int t = 1; 28 while(EOF != scanf("%d %d %d",&l, &n, &m) ) { 29 for(int i = 0; i < l; i++) scanf("%d",&a[i]); 30 for(int i = 0; i < n; i++) scanf("%d",&b[i]); 31 for(int i = 0; i < m; i++) scanf("%d",&c[i]); 32 cnt = 0; 33 for(int i = 0; i < l; i++) { 34 for(int j = 0; j < n; j++) { 35 d[cnt++] = a[i] + b[j]; 36 } 37 } 38 sort(d, d + cnt); 39 int s; 40 int num; 41 printf("Case %d:\n", t++); 42 scanf("%d",&s); 43 while(s--) { 44 scanf("%d",&num); 45 bool flag = false; 46 for(int i = 0; i < m; i++) { 47 if(check(num - c[i]) ) { 48 flag = true; 49 break; 50 } 51 } 52 if(flag) puts("YES"); 53 else puts("NO"); 54 } 55 } 56 }
标签:des style blog http io color os ar for
原文地址:http://www.cnblogs.com/zhanzhao/p/4063532.html