码迷,mamicode.com
首页 > 其他好文 > 详细

HNU11376:Golf Bot

时间:2015-08-10 20:01:23      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:hnu

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


版权声明:本文为博主原创文章,未经博主允许不得转载。

HNU11376:Golf Bot

标签:hnu

原文地址:http://blog.csdn.net/libin56842/article/details/47403569

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!