嘛,从最开始的gcd(n,dx)=gcd(n,dy)=1可以发现互素性质
这样的话很容易脑补出在n×n的方格中,存在着的我们找到的苹果树【?】一定是一列而不是多列【有点绕口
这样的话我们只要算偏移量就行啦
比如将经过(0,0)的一列斜率为dy/dx的直线偏移量设为0
那么经过(1,0)的直线偏移量为1
这样可以把二维的统计计算转化为一维
That’s all
#include<iostream>
#include<stdio.h>
using namespace std;
const int maxn=1000005;
int n,m,dx,dy,x,y,s[maxn],d[maxn],maxa,z,temp;
int main(void)
{
scanf("%d%d%d%d",&n,&m,&dx,&dy);
for(int i=0;i<n;i++)
{
s[x]=y;
x+=dx;x%=n;
y+=dy;y%=n;
}
for(int j=0;j<m;j++)
{
scanf("%d%d",&x,&y);
temp=y-s[x];
if(temp<0)temp=n+temp;
d[temp]++;
if(d[temp]>maxa)maxa=d[temp],z=temp;
}
printf("0 %d\n",z);
return 0;
}