跳到正文

题解

题解:P8695 [蓝桥杯 2019 国 AC] 轨道炮

PoZnHe约 2 分钟
原文
文章信息与版本

文章信息

发布
2026年7月19日
收录
2026年7月19日
更新
2026年11月9日
篇幅
约 2 分钟
获赞
1
题目
P8695

版本

  1. v2当前
  2. v1

1.思路

定义变量

观察到题目标签数据范围是 N≤1000N \le 1000 ,范围较小,考虑用暴力枚举做法。

定义结构体 nodenode ,并存储 44 个变量, x,y,vx,vyx,y,vx,vy 。 x,yx,y 表示横纵坐标, vx,vyvx,vy 表示在横纵方向的运动速度。

枚举时间

我们设桶 tx,tytx,ty 为某一时刻某一 xx 或 yy 坐标上敌人的数量,记录每个时刻的 tx,tytx,ty ,取最大值。

注意到坐标范围 −106≤Xi,Yi≤106 -10^6 \le X_i,Y_i \le 10^6 ,用数组会出现一些奇奇怪怪的错误,比如 RE,MLE 之类,所以我们用 map 来存储。

时间枚举到 11451145 足矣。(好臭的数字)

2.AC代码

仅供参考,不要抄袭,抄袭不会使你得到提升。

码风较丑见谅。

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n;
struct node{
	int x,y,vx,vy;
}a[1001];
signed main(){	
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i].x>>a[i].y;
		int v;
		cin>>v;
		char op;
		cin>>op;
		if(op=='U') a[i].vy=v;
		if(op=='D') a[i].vy=-v;
		if(op=='L') a[i].vx=-v;
		if(op=='R') a[i].vx=v;
	}
	int maxn=-1;
	for(int i=0;i<=1145;i++){
		map<int,int> tx,ty;
		for(int j=1;j<=n;j++){
			tx[a[j].x+a[j].vx*i]++;
			ty[a[j].y+a[j].vy*i]++;
		}
		for(auto j:tx) maxn=max(maxn,j.second);
		for(auto j:ty) maxn=max(maxn,j.second); 
	}
	cout<<maxn;
	return 0;
}
原文