很有意思的一道题:
在正方形中按一个固定向量走,路过最多的特殊点。
注意,dx与n互质,dy与n互质,意味着走n步必然回到起点,且路径上同一个横坐标只会对应一个纵坐标。
所以,就简化成一个分类计数问题。
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#define maxn 1000010
int ans[maxn];
int res[maxn];
int memory[maxn][2];
int main()
{
int n,m,dx,dy;
scanf("%d%d%d%d",&n,&m,&dx,&dy);
memset(ans,0,sizeof(ans));
memset(res,0,sizeof(res));
int x = 0;
int y = 0;
for(int i=0;i<n;i++)
{
x = (x+dx)%n;
y = (y+dy)%n;
ans[x] = y;
}
for(int i=0;i<m;i++)
{
int tx,ty;
scanf("%d%d",&tx,&ty);
int loc = 0;
if(ty < ans[tx]) loc = n - ans[tx] + ty ;
else loc = ty - ans[tx];
res[loc]++;
memory[loc][0] = tx;
memory[loc][1] = ty;
}
int maxans = 0;
int maxloc = 0;
for(int i=0;i<n;i++)
{
if(maxans < res[i])
{
maxans = res[i];
maxloc = i;
}
}
printf("%d %d\n",memory[maxloc][0],memory[maxloc][1]);
return 0;
}