Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/Others)
Total Submission(s): 35836 Accepted Submission(s):
8845
1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cmath> 5 #define xps 1e-12 6 using namespace std; 7 long long a[510], b[510], c[510], d[250010]; 8 int main() 9 { 10 long long l, m, n, o = 1; 11 while (cin >> l >> m >> n) 12 { 13 for (int i = 0; i<l; i++)//输入三个数组 14 cin >> a[i]; 15 for (int i = 0; i<m; i++) 16 cin >> b[i]; 17 for (int i = 0; i<n; i++) 18 cin >> c[i]; 19 int k = 0; 20 for (int i = 0; i<l; i++) 21 for (int j = 0; j<m; j++) 22 d[k++] = a[i] + b[j];//前两个数组两两相加得到新数组 23 sort(d, d + k);//从小到大排序 24 int s; 25 cin >> s; 26 cout << "Case " << o++ << ":" << endl;//输出第几个测试实例 27 while (s--) 28 { 29 long long x; 30 cin >> x; 31 bool sign = false; 32 for (int i = 0; i<n; i++)//第三个数组和新数组mid相加判断 33 { 34 int l = 0, r = k - 1; 35 while (l <= r) 36 { 37 int mid = (l + r) / 2; 38 if (d[mid] + c[i] == x) 39 { 40 sign = 1; 41 break; 42 } 43 else if (d[mid] + c[i] < x) 44 { 45 l = mid+1; 46 } 47 else r = mid-1; 48 } 49 if (sign) break; 50 } 51 if (sign) 52 cout << "YES" << endl; 53 else 54 cout << "NO" << endl; 55 } 56 } 57 return 0; 58 }