①使用binary_search前要先保证有序

②binary_search函数仅返回true或false

③binary_search(first element, laste lment + 1, data to search)

 #include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
using namespace std;
struct PLANT{
int x, y;
};
PLANT map[];
int r, c, num;
int max_num; bool operator < (const PLANT & p1, const PLANT & p2){
if(p1.x == p2.x) return p1.y < p2.y;
return p1.x < p2.x;
} int function(int dx, int dy, int x, int y){
int flag = ;
while(x >= && x <= r && y >= && y <= c){
PLANT temp;
temp.x = x;
temp.y = y;
if(!binary_search(map, map+num, temp)) return ;
x += dx;
y += dy;
++flag;
}
return flag;
}
int main(){
int i, j, k, t;
int num_x, num_y;
int flag;
scanf("%d%d",&r,&c);
scanf("%d",&num);
for(i = ; i < num; ++i) scanf("%d%d",&map[i].x,&map[i].y); sort(map, map+num);
max_num = ; for(i = ; i < num; ++i){
for(j = i + ; j < num; ++j){
int dx = map[j].x - map[i].x;
int dy = map[j].y - map[i].y;
int px = map[i].x - dx;
int py = map[i].y - dy;
if(px >= && px <= r && py >= && py <= c) continue; if(map[i].x + max_num * dx > r) continue;
int pY = map[i].y + max_num * dy;
if(pY > c || pY < ) continue; px = dx + map[j].x;
py = dy + map[j].y;
int flag = ;
while(px >= && px <= r && py >= && py <= c){
PLANT temp;
temp.x = px;
temp.y = py;
if(!binary_search(map, map+num, temp)){
flag = ;
break;
}
px += dx;
py += dy;
++flag;
}
max_num = max(max_num, flag);
}
}
if(max_num == ) printf("0\n");
else printf("%d\n",max_num);
return ;
}
05-08 14:57