标签:pre 剪枝 memset mat continue bool include pac math
#include<iostream>
#include<memory.h>
#include<cmath>
#include<algorithm>
using namespace std;
typedef struct
{
int x, y;
}node;
node d[6000];
int r, c;
int n;
bool map[6000][6000];
int ans = 0;
bool cmp(node a, node b)
{
if(a.y == b.y) return a.x<b.x;
else return a.y<b.y;
}
void solve()
{
for(int i = 0; i < n; i++)
{
for(int j = i+1; j < n; j++)
{
int x = d[i].x, y = d[i].y;
int vx = d[j].x-d[i].x, vy = d[j].y-d[i].y;
if(y+ans*vy > c) break; //剪枝
if(x+ans*vx > r) continue; //后面的 x 可能比前面的小,所以用continue
if(ans == (r>c?r:c)) return; //剪枝
if(x-vx >= 1 && x-vx <= r && y-vy >= 1 && y-vy <= c) continue; //前面的点在图内
int d = 2;
while(x+d*vx >= 1 && x+d*vx <= r && y+d*vy >= 1 && y+d*vy <= c && map[x+d*vx][y+d*vy]) d++;
if(d >= 3)
if(x+d*vx < 1 || x+d*vx > r || y+d*vy < 1 || y+d*vy > c)
ans = d>ans ? d:ans;
}
}
}
int main()
{
cin >> r >> c;
cin >> n;
memset(map, false, sizeof map);
for(int i = 0; i < n; i++)
{
cin >> d[i].x >> d[i].y;
map[d[i].x][d[i].y] = true;
}
sort(d, d+n, cmp); //预先排序
solve();
cout << ans;
system("pause");
return 0;
}
标签:pre 剪枝 memset mat continue bool include pac math
原文地址:https://www.cnblogs.com/znk97/p/13942646.html