pku 1054 二分
#include <iostream>
#include <algorithm>
using namespace std;
int n, m, t;
class Point
{
public:
int x, y;
bool operator<(const Point &b)
{
if (x == b.x)
{
return y < b.y;
}
else
{
return x < b.x;
}
}
} point[5010];
bool search(Point a)
{
int low = 0, high = t;
while (low <= high)
{
int mid = (low + high) / 2;
if (point[mid] < a)
{
low = mid + 1;
}
else if (a < point[mid])
{
high = mid - 1;
}
else
{
return true;
}
}
return false;
}
int solve()
{
int max = 0;
int i, j;
for (i = 0; i < t; ++i)
{
for (j = i + 1; j < t; ++j)
{
int temp = 2;
Point fx, fy, jump, next;
fx = point[i];
fy = point[j];
jump.x = point[j].x - point[i].x;
jump.y = point[j].y - point[i].y;
if (fx.x - jump.x > 0 && fx.x - jump.x <= n && fx.y - jump.y > 0 && fx.y - jump.y <= m)
{
continue;
}
else if (fx.x + max * jump.x <= 0 || fx.x + max * jump.x > n || fx.y + max * jump.y <= 0 || fx.y + max * jump.y > m)
{
continue;
}
next.x = fy.x + jump.x;
next.y = fy.y + jump.y;
while (next.x > 0 && next.x <= n && next.y > 0 && next.y <= m)
{
if (search(next))
{
temp++;
next.x += jump.x;
next.y += jump.y;
}
else
{
temp = 0;
break;
}
}
if (temp > max)
{
max = temp;
}
}
}
return max;
}
int main()
{
while (scanf("%d %d", &n, &m) != EOF)
{
scanf("%d", &t);
int i;
for (i = 0; i < t; ++i)
{
scanf("%d %d", &point[i].x, &point[i].y);
}
sort(point, point + t);
int temp = solve();
if (temp > 2)
{
printf("%d"n", temp);
}
else
{
printf("0"n");
}
}
return 0;
}
浙公网安备 33010602011771号