HNU11376:Golf Bot

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 has one integer, ki, the distance marked in position i of the knob.
Next line has one integer: M, the number of holes in this course. Each of the following M lines has 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 will be able to complete. Golf Bot cannot shoot over a hole on purpose and then shoot backwards.


Sample Input
3
1
3
5
6
2
4
5
7
8
9
Sample Output
4
Problem Source
HNU Contest 


题意:

打高尔夫。一球能打n种距离。有m个洞,给出每一个洞的位置。问两杆之内,在仅仅能往前打的情况下。能进的有几种洞


思路:

数据非常大?但你要看有30S。明摆着告诉你暴力可行

#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 rank1
const 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;
}


posted @ 2017-05-03 17:55  cxchanpin  阅读(216)  评论(0编辑  收藏  举报