题解:P8695 [蓝桥杯 2019 国 AC] 轨道炮
jackwahaha · · 题解
题目
思路
学过动点的人都知道,表示一个点可以用如下公式(其中
在这里,二维直角坐标系上考虑
代码
#include <iostream>
#include <map>
using namespace std;
#define int long long
#pragma G++ optimize(2)
int n,ans;
struct node{
int sx,sy,vx,vy;//s是起始点,v是速度
}a[1005];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
int x,y,v;
char d;
cin>>x>>y>>v>>d;
a[i].sx=x,a[i].sy=y;
if(d=='U'){//上
a[i].vx=0;//x轴不动
a[i].vy=v;//y轴向正方向移动
}
else if(d=='D'){//下
a[i].vx=0;//x轴不动
a[i].vy=-v;//y轴向负方向移动
}
else if(d=='L'){//左
a[i].vx=-v;//x轴向负方向移动
a[i].vy=0;//y轴不动
}
else if(d=='R'){//右
a[i].vx=v;//x轴向正方向移动
a[i].vy=0;//y轴不动
}
}
for(int i=0;i<=1111;i++){//遍历时间
map <int,int> x,y;
for(int j=1;j<=n;j++){//装桶
x[a[j].sx+a[j].vx*i]++;//套公式
y[a[j].sy+a[j].vy*i]++;
}
for(auto j=x.begin();j!=x.end();j++){//x轴最大值
ans=max(ans,j->second);
}
for(auto j=y.begin();j!=y.end();j++){//y轴最大值
ans=max(ans,j->second);
}
}
cout<<ans;
return 0;
}
//AC!!!