#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define N 5003
#define prim 10079
int r,c,n;
struct point
{
int x,y;
int next;// point to next point's number
bool operator<(const struct point &u) const
{
if(y == u.y)
return x return y }
};
int dp[N][N]; //存放j延伸到i射线上点的个数
int hash[prim];//hash 链表
point pn[N];
bool inner(int x,int y) //是否在田地范围内
{
return (x>=1 && x<=r && y>=1 && y<=c);
}
int hash_func(int x,int y) //hash 函数,这里完全是要这个函数优劣了
{
return (x+y+x*y)%prim;
}
int hash_find(int x,int y) //有这样的需求
{
int h = hash_func(x,y);
int j = hash[h];
while(j!=-1)
{
if(x == pn[j].x && y == pn[j].y)
return j;
j = pn[j].next;
}
return -1;
}
void hash_insert(const struct point & p,int i)
{
int h= hash_func(p.x,p.y);
pn[i].next = hash[h];
hash[h]=i;
}
int main()
{
#ifdef LOCAL
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);
#endif
cin>>r>>c;
cin>>n;
memset(hash,0xff,sizeof(hash)); //all FFFFF
int i,j;
for(i=0;i scanf("%d %d",&pn[i].x,&pn[i].y);
sort(pn,pn+n); //为dp 规定一个顺序,状态转移必须,明确位置关系
for(i=0;i printf("%d %d\t",pn[i].x,pn[i].y);
cout< int ha;
for(i=0;i hash_insert(pn[i],i);
int x0,y0,x1,y1,maxp = 2;
for(i=1;i {
for(j=0;j {
x0 = 2*pn[j].x - pn[i].x; //pn[j].x<=pn[i].x,因为排过序了
y0 = 2*pn[j].y - pn[i].y;
if(inner(x0,y0))
{
ha = hash_find(x0,y0); //找点号
if( ha !=-1 && dp[j][ha]!=-1)
dp[i][j] = dp[j][ha] +1; //转移很巧妙,要点几何知识,
else
dp[i][j] = -1; //此条射线以后也无法满足要求,能进必然能出,否则不是合法轨迹
}
else dp[i][j]=2;
x1 = 2*pn[i].x - pn[j].x;
y1 = 2*pn[i].y - pn[j].y;
if(!inner(x1,y1)) //不可以再向右延伸了,记录最大数
{
maxp = max(maxp,dp[i][j]);
printf("dp[%d][%d]=%d\n",i,j,dp[i][j]);
}
}
}
if(maxp>2)
cout< else
cout<<0;
return 0;
}
阅读(653) | 评论(0) | 转发(0) |