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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值