题目链接:POJ 3119 Friends or Enemies?
题意应该好理解的,就是在一个二维坐标系中,序列成顺时针螺旋分布,在给出直线的y=ax+b,问给出的两点是否在同一侧。
思路:模拟记录点分布的坐标。再依次判断。
用一个函数画出红色部分。循环处理下,就得到分布图了。
AC代码:
#include<stdio.h>
#include<string.h>
int count;
struct node
{
int x,y;
};
struct node p[70000];
node build(int x,int y,int size,int a,int b)
{
node ans;
int i,j,xx,yy;
xx=x,yy=y;
for(i=1;i<size;i++)//横左
{
if(a*xx+b==yy);
else
{
p[count].x=xx;
p[count++].y=yy;
}
xx--;
}
for(i=1;i<size;i++)//竖上
{
if(a*xx+b==yy);
else
{
p[count].x=xx;
p[count++].y=yy;
}
yy++;
}
for(i=1;i<size+1;i++)//横右
{
if(a*xx+b==yy);
else
{
p[count].x=xx;
p[count++].y=yy;
}
xx++;
}
for(i=1;i<size+1;i++)//竖下
{
if(a*xx+b==yy);
else
{
p[count].x=xx;
p[count++].y=yy;
}
yy--;
}
ans.x=xx,ans.y=yy;
return ans;
}
int main()
{
int i,j;
int a,b,m,t;
int aa,bb,cas=1;
while(scanf("%d",&t)!=EOF)
{
while(t--)
{
node q;
printf("Caso %d\n",cas++);
scanf("%d %d",&a,&b);
q.x=q.y=count=0;
for(i=2;i<=260;i+=2)
q=build(q.x,q.y,i,a,b);
scanf("%d",&m);
for(i=0;i<m;i++)
{
scanf("%d %d",&aa,&bb);
int temp1,temp2;
temp1=p[aa].y-a*p[aa].x-b;
temp2=p[bb].y-a*p[bb].x-b;
if(temp1*temp2<0)
printf("Lados opostos da fronteira\n");
else
printf("Mesmo lado da fronteira\n");
}
}
}
return 0;
}