URAL_1021
可以将问题等效成对于x查找10000-x是否在列表中出现过,二分、哈希等都可以。
#include#include #define D 33000#define MAXD 66000#define MIN -32768#define MAX 32767int N, h[MAXD];void init(){ int i, k; memset(h, 0, sizeof(h)); for(i = 0; i < N; i ++) { scanf("%d", &k); h[D + k] = 1; }}void solve(){ int i, j, k, ok = 0; scanf("%d", &N); for(i = 0; i < N; i ++) { scanf("%d", &k); k = 10000 - k; if(k >= MIN && k <= MAX && h[D + k]) ok = 1; } printf("%s\n", ok ? "YES" : "NO");}int main(){ while(scanf("%d", &N) == 1) { init(); solve(); } return 0;}