Hnu11376:golf Bot

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.