Problem description |
|
Input |
The first line has one integer:n, the number of different distances the Golf Bot can shoot. Each of the following N lines have one integer, Ki, the distance marked in position I of the knob. Next Line have one integer:m, the number of holes in this course. Each of the following M lines have one integer, DJ, the distance from Golf Bot to Hole J. 1<=n,m<=200 000 1<=ki,dj<=200 000
|
Output |
You should output a single integer, the number of holes Golf Bot would be able to complete. Golf Bot cannot shoot over a hole in purpose and then shoot backwards.
|
Sample Input |
31356245789 |
Sample Output |
4 |
Problem Source |
Hnu Contest |
Test instructions
Play golf, a ball can play n kinds of distance, there are m holes, give each hole position, ask two, in the case can only go forward, can enter a few holes
Ideas:
Data is large? But you have to look at 30S, and it's obvious that violence is possible.
#include <iostream> #include <stdio.h> #include <string.h> #include <stack> #include <queue > #include <map> #include <set> #include <vector> #include <math.h> #include <bitset># Include <algorithm> #include <climits>using namespace std; #define LS 2*i#define rs 2*i+1#define up (i,x,y) for (i=x;i<=y;i++) #define DOWN (i,x,y) for (i=x;i>=y;i--) #define MEM (a,x) memset (A,x,sizeof (a)) #define W (a) while (a) #define GCD (A, B) __gcd (A, b) #define LL long long#define N 200005#define INF 0x3f3f3f3f#define EXP 1e-8#define rank Rank1con St int mod = 1000000007;int hsh[n*2];int a[n],b[n];int main () {int n,m,i,j,k; while (~SCANF ("%d", &n)) {MEM (hsh,0); for (i = 0; i<n; i++) {scanf ("%d", &a[i]); Hsh[a[i]] = 1; } sort (a,a+n); for (i = 0; i<n; i++) {for (j = i; j<n; j + +) {Hsh[a[i]+a[j]] = 1; } } int ans = 0; scanf ("%d", &m); for (i = 0; i<m; i++) {scanf ("%d", &b[i]); if (Hsh[b[i]]) ans++; } printf ("%d\n", ans); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Hnu11376:golf Bot