鏈接:http://poj.org/problem?id=1054node
題意:就是一個格子裏一條線上最長有幾個青蛙(青蛙間隔相同)~。可是其實青蛙的起點重點必須是在外面。ios
直接寫一個搜就是。ide
1 #include <stdio.h> 2 #include <string.h> 3 #include <iostream> 4 #include <algorithm> 5 #include <stdlib.h> 6 #include <vector> 7 #include <queue> 8 #include <stack> 9 #define loop(s,i,n) for(i = s;i < n;i++) 10 #define cl(a,b) memset(a,b,sizeof(a)) 11 using namespace std; 12 int map[5005][5005]; 13 int r,c,n; 14 struct node 15 { 16 int x,y; 17 }p[50005]; 18 int cmp( struct node a, struct node b) 19 { 20 if(a.x == b.x) 21 return a.y < b.y; 22 return a.x < b.x; 23 } 24 int judge(int x,int y) 25 { 26 if(x >= 1 && x <= r && y >= 1&&y <= c) 27 return 1; 28 29 return 0; 30 31 } 32 int find(struct node tmp,int dx,int dy) 33 { 34 35 int ans = 2; 36 37 int leap =1; 38 while(judge(tmp.x+dx,tmp.y+dy)) 39 { 40 if(map[tmp.x+dx][tmp.y+dy]) 41 { 42 tmp.x+= dx,tmp.y += dy; 43 ans++; 44 } 45 else 46 { 47 leap = 0; 48 break; 49 } 50 } 51 if(leap) 52 return ans; 53 return 0; 54 } 55 int main() 56 { 57 while(~scanf("%d %d",&r,&c)) 58 { 59 int i,j; 60 scanf("%d",&n); 61 62 cl(map,0); 63 for(i = 1;i <= n;i++) 64 scanf("%d %d",&p[i].x,&p[i].y),map[p[i].x][p[i].y] = 1; 65 66 sort(p+1,p+n+1,cmp); 67 int ans = 0; 68 for(i = 1;i <= n;i++) 69 { 70 71 for(j = i+1;j <= n;j++) 72 { 73 74 int dx,dy; 75 dx = p[j].x-p[i].x; 76 dy = p[j].y-p[i].y; 77 struct node tmp; 78 tmp = p[j]; 79 if(judge(p[i].x-dx,p[i].y-dy)) 80 continue; 81 int cnt = find(tmp,dx,dy); 82 83 if(ans < cnt) 84 ans = cnt; 85 86 } 87 } 88 if(ans < 3) 89 puts("0"); 90 else 91 printf("%d\n",ans); 92 } 93 return 0; 94 }