解题思路:这道题其实比较简单,就是找斜率相同且间距相同的点。
首先,就是要找到两点,确定好斜率,然后就判断这两点是否在起始位置。
其次,确定好斜率就确定了两个点之间的距离,如果某两点之间的间距不满足的话,那么这个点肯定不是这个方向上的。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
const int maxn = 5005;
struct node
{
int row,col;
int next;
}p[maxn];
int r,c,n;
bool vis[maxn][maxn];
bool cmp(node a,node b)
{
if(a.col == b.col) return a.row < b.row;
return a.col < b.col;
}
int main()
{
while(scanf("%d%d",&r,&c)!=EOF)
{
scanf("%d",&n);
memset(vis,false,sizeof(vis));
for(int i = 1; i <= n; i++)
{
scanf("%d%d",&p[i].row,&p[i].col);
vis[p[i].row][p[i].col] = true;
}
std::sort(p+1,p+1+n,cmp);
int ans = 0;
for(int i = 1; i <= n; i++)
for(int j = i + 1; j <= n; j++)
{
int disx = p[j].row - p[i].row;
int disy = p[j].col - p[i].col;
if(p[i].row - disx > 0 && p[i].row - disx <= r && p[i].col - disy > 0 && p[i].col - disy <= c) continue;
int tmpx = p[j].row + disx;
int tmpy = p[j].col + disy;
int cnt = 0;
while(tmpx > 0 && tmpx <= r && tmpy > 0 && tmpy <= c)
{
if(vis[tmpx][tmpy]) cnt++;
else
{
cnt = 0; break;
}
tmpx += disx;
tmpy += disy;
}
ans = std::max(ans,cnt);
}
if(ans) printf("%d\n",ans+2);
else printf("%d\n",ans);
}
return 0;
}