poj1054 The Troublesome Frog 瞎搞。

连接:http://poj.org/problem?id=1054

题意:就是一个格子里一条线上最长有几个青蛙(青蛙间隔相同)~。但是其实青蛙的起点重点必须是在外面。

直接写一个搜就是。

 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <stack>
#define loop(s,i,n) for(i = s;i < n;i++)
#define cl(a,b) memset(a,b,sizeof(a))
using namespace std;
int map[][];
int r,c,n;
struct node
{
int x,y;
}p[];
int cmp( struct node a, struct node b)
{
if(a.x == b.x)
return a.y < b.y;
return a.x < b.x;
}
int judge(int x,int y)
{
if(x >= && x <= r && y >= &&y <= c)
return ; return ; }
int find(struct node tmp,int dx,int dy)
{ int ans = ; int leap =;
while(judge(tmp.x+dx,tmp.y+dy))
{
if(map[tmp.x+dx][tmp.y+dy])
{
tmp.x+= dx,tmp.y += dy;
ans++;
}
else
{
leap = ;
break;
}
}
if(leap)
return ans;
return ;
}
int main()
{
while(~scanf("%d %d",&r,&c))
{
int i,j;
scanf("%d",&n); cl(map,);
for(i = ;i <= n;i++)
scanf("%d %d",&p[i].x,&p[i].y),map[p[i].x][p[i].y] = ; sort(p+,p+n+,cmp);
int ans = ;
for(i = ;i <= n;i++)
{ for(j = i+;j <= n;j++)
{ int dx,dy;
dx = p[j].x-p[i].x;
dy = p[j].y-p[i].y;
struct node tmp;
tmp = p[j];
if(judge(p[i].x-dx,p[i].y-dy))
continue;
int cnt = find(tmp,dx,dy); if(ans < cnt)
ans = cnt; }
}
if(ans < )
puts("");
else
printf("%d\n",ans);
}
return ;
}
上一篇:Kmeanns图片压缩


下一篇:FreeMarker 乱码解决方案 生成静态html文件