6886 - Golf Bot

6886 Golf Bot
Do you like golf? I hate it. I hate golf so much that I
decided to build the ultimate golf robot, a robot that
will never miss a shot. I simply place it over the ball,
choose the right direction and distance and, flawlessly,
it will strike the ball across the air and into the hole.
Golf will never be played again.
Unfortunately, it doesn’t work as planned. So, here
I am, standing in the green and preparing my first
strike when I realize that the distance-selector knob
built-in doesn’t have all the the distance options! Not ev-
erything is lost, as I have 2 shot.

Given my current robot, how many holes will I be
able to complete in 2 strokes or less? The ball must be
always on the right line between the tee and the hole.
It isn’t allowed to overstep it and come back.
Input
The input file contains several test cases, each of them
as described below.
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.
Constraints:
1 <= N; M <= 200 000
1 <= ki; dj <= 200 000
Output
For each test case, 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 Output Explanation
Golf Bot can shoot 3 different distances (1, 3 and 5) and there are 6 holes in this course at distances
2, 4, 5, 7, 8 and 9. Golf Bot will be able to put the ball in 4 of these:
• The 1st hole, at distance 2, can be reached by striking two times a distance of 1.
• The 2nd hole, at distance 4, can be reached by striking with strength 3 and then strength 1 (or
vice-versa).
• The 3rd hole can be reached with just one stroke of strength 5.
• The 5th hole can be reached with two strikes of strengths 3 and 5.
Holes 4 and 6 can never be reached.
Sample Input
3
1
3
5
6
2
4
5
7
8
9
Sample Output
4

直接暴力会超时,简单hash一下即可。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long ll;
#define MAX 1005
#define PI acos(-1.0)
int a[200005],b[200005];
int f[200005];
int main(){
	int n,m; 
	while(~scanf("%d", &n)){
		memset(f,0,sizeof(f));
		for(int i = 0;i < n;i++){
			scanf("%d", a+i);
			f[a[i]] = 1;	
		}
		scanf("%d", &m);
		sort(a,a+n);
		int cnt = 0;
		for(int i = 0;i < m;i++){
			int num;
			scanf("%d", &num);
			if(f[num]){
				cnt ++;
				continue;
			}
			for(int i = 0;i < n;i++){
				if(2*a[i] > num){
					break;
				}
				if(f[num-a[i]]){
					cnt ++;
					break;
				}
			}
		}
		printf("%d\n", cnt);
	} 
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CMake是一种跨平台的构建工具,用于管理C++项目的构建过程。CMake的配置文件是CMakeLists.txt,该文件描述了项目的目录结构和构建规则。在使用CMake构建项目时,可以通过创建CMakeLists.txt文件来指定项目的目录结构和生成所需的构建规则。 在VSCode中使用CMake可以方便地管理项目,并使用强大的编辑器功能进行开发。通过在VSCode中配置CMake插件,可以自动检测和配置CMake项目,使得构建过程更加简便。在VSCode中,可以通过在项目文件夹中创建CMakeLists.txt文件,并使用CMake插件来执行构建和调试操作。 目录结构在CMake项目中起着重要的作用,它有助于组织和管理项目中的源代码、头文件、库文件等资源。常见的CMake项目目录结构通常包括src目录用于放置源代码文件、include目录用于放置头文件、lib目录用于放置库文件等。通过明确的目录结构,可以使得项目文件的组织更加清晰,便于开发者理解和维护项目。 对于一个golf项目来说,我们可以将其分为多个模块或功能,每个模块对应一个子目录。比如,我们可以创建一个src目录用于放置主程序的源代码文件,一个include目录用于放置头文件,一个tests目录用于放置测试文件等。然后,在CMakeLists.txt中,可以通过add_executable来添加主程序,使用add_library来添加库文件,使用target_link_libraries来链接所需的库文件等。 总之,CMake是一个强大的构建工具,配合VSCode的插件,可以方便地管理和构建C++项目。通过合理的目录结构和CMakeLists.txt文件的配置,能够更好地组织和管理项目资源,提高开发效率和代码质量。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值