通过题目描述我们可以知道,如果通过观察寻找规律几乎很难做出,因此我们可以用枚举来列举所有时间(限制1000即可)内每个单位的状态,并用哈希表来存储某个坐标的数量,并记录最大值,最后直接输出答案即可
上代码
#include<iostream>
#include<cstring>
#include<algorithm>
#include<unordered_map>
using namespace std;
const int N = 1010;
int x[N], y[N], v[N];
char d[N];
int main(void)
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n;
for(int i = 1; i <= n; i++){//输入数据
cin >> x[i] >> y[i] >> v[i] >> d[i];
}
int ans = 0;
for(int i = 0; i <= 1000; i++){//枚举从1到1000时刻的状态并找出最大值
unordered_map <int,int> mpx, mpy;//存储每个时刻每个坐标对应的值
for(int j = 1; j <= n; j++){//枚举每个时刻每个单位的状态
if(d[j] == 'R'){//向右
mpx[x[j] + v[j] * i]++;
mpy[y[j]]++;
}
else if(d[j] == 'L'){//向左
mpx[x[j] - v[j] * i]++;
mpy[y[j]]++;
}
else if(d[j] == 'D'){//向下
mpx[x[j]]++;
mpy[y[j] - v[j] * i]++;
}
else if(d[j] == 'U'){//向上
mpx[x[j]]++;
mpy[y[j] - v[j] * i]++;
}
}
for(auto p = mpx.begin(); p != mpx.end(); p++){
ans = max(ans, (*p).second);
}
for(auto p = mpy.begin(); p != mpy.end(); p++){
ans = max(ans, (*p).second);
}
}
cout << ans << endl;
return 0;
}