Codeforces #140 dv2 结题报告
A
这道题可以有多种方法求解 。
1.我使用了最笨的一种,是较丑的一种 就是分类讨论然后再用在讨论c点的位置 然后在讨论K的正负,,教笨;
2.学长使用的是象限方法讨论 因为确定了为直线关系,所以每个象限之间又会有不同的特性
3.最为快速的一种方法 使用的是向量积,来判断z轴向量的正负就可以判断左右转动。证明如下图所示。
下面是三种方法的代码
# include <stdio.h>
int main()
{
int mark;
__int64 a,b,c,d,e,f;
double k,g;
while(scanf("%I64d%I64d%I64d%I64d%I64d%I64d",&a,&b,&c,&d,&e,&f)!=EOF)
{
if(0==(b-d))
{
if(a>c&&f>d)
{printf("RIGHT\n");continue;}
else if(a>c&&f<d)
{printf("LEFT\n");continue;}
if(a<c&&f>d)
{printf("LEFT\n");continue;}
else if(a<c&&f<d)
{printf("RIGHT\n");continue;}
else
{printf("TOWARDS\n");continue;}
}
else if(0==(a-c))
{
if(d>b&&e<c)
{printf("LEFT\n");continue;}
if(d>b&&e>c)
{ printf("RIGHT\n");continue;}
if(d<b&&e<c)
{printf("RIGHT\n");continue;}
if(d<b&&e>c)
{printf("LEFT\n");continue;}
else
printf("TOWARDS\n");
}
else
{
if(((a-c)*(b-f))==((b-d)*(a-e)))
{printf("TOWARDS\n");continue;}
k=(double)(b-d)/(a-c);
g=(double)b-k*a;
if((k*e+g-f)>0)
{
mark=1;
}
else
{
mark=0;
}
if(k>0)
{
if(d>b)
{
if(!mark)
{printf("LEFT\n");continue;}
else
{printf("RIGHT\n");continue;}
}
else
{
if(!mark)
{printf("RIGHT\n");continue;}
else
{printf("LEFT\n");continue;}
}
}
else
{
if(b>d)
{
if(!mark)
{printf("LEFT\n");continue;}
else
{printf("RIGHT\n");
continue;}
}
else
{
if(!mark)
{printf("RIGHT\n");continue;}
else
{printf("LEFT\n");continue;}
}
}
}
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main()
{
__int64 x1,y1,x2,y2,x3,y3;
while(scanf("%I64d %I64d", &x1, &y1)!=EOF)
{
scanf("%I64d %I64d", &x2, &y2);
scanf("%I64d %I64d", &x3, &y3);
if( (x2-x1)*(y3-y2)==(y2-y1)*(x3-x2) )
{
printf("TOWARDS\n");
}
else
{
if(x2-x1>=0 && y2-y1>0)
{
if(x3-x2>0) printf("RIGHT\n");
else printf("LEFT\n");
}
else if(x2-x1<=0 && y2-y1<0)
{
if(x3-x2>0) printf("LEFT\n");
else printf("RIGHT\n");
}
else if(x2-x1<0 && y2-y1>=0)
{
if(y3-y2>0) printf("RIGHT\n");
else printf("LEFT\n");
}
else if(x2-x1>0 && y2-y1<=0)
{
if(y3-y2>0) printf("LEFT\n");
else printf("RIGHT\n");
}
}
}
return 0;
}
#include<cstdio>
#include<cstring>
#include<cmath>
#include<set>
#include<algorithm>
using namespace std;
#define LL long long
struct point
{
LL x,y;
} x[3];
LL crossProduct(point a,point b,point c)//向量 ac 在 ab 的方向 顺时针是正
{
return (c.x-a.x)*(b.y-a.y)-(b.x - a.x)*(c.y-a.y);
}
int main()
{
for(int i=0; i<3; ++i)
scanf("%I64d%I64d",&x[i].x,&x[i].y);
if((x[2].y-x[1].y)*(x[1].x-x[0].x)==(x[1].y-x[0].y)*(x[2].x-x[1].x))
puts("TOWARDS");
else if(crossProduct(x[2],x[1],x[0])<0)
puts("RIGHT");
else
puts("LEFT");
return 0;
}