输入
2
1.000000 0.000000
10.000000 0.000000
10.000000 8.000000
9.000000 8.000000
9.000000 5.000000
8.000000 5.000000
8.000000 10.000000
7.000000 10.000000
7.000000 5.000000
6.000000 5.000000
6.000000 10.000000
5.000000 10.000000
5.000000 5.000000
4.000000 5.000000
4.000000 10.000000
3.000000 10.000000
3.000000 3.000000
2.000000 3.000000
2.000000 6.000000
1.000000 6.000000
-1.000123 0.000000
-10.000123 0.000000
-10.000123 8.000000
-9.000123 8.000000
-9.000123 5.000000
-8.000123 5.000000
-8.000123 10.000000
-7.000123 10.000000
-7.000123 5.000000
-6.000123 5.000000
-6.000123 10.000000
-5.000123 10.000000
-5.000123 5.000000
-4.000123 5.000000
-4.000123 10.000000
-3.000123 10.000000
-3.000123 3.000000
-2.000123 3.000000
-2.000123 6.000000
-1.000123 6.000000
输出
right
left
思路分析:
还是先说一下坐标的叉乘和点乘把,好多都忘记了
向量的点乘:a * b
公式:a * b = |a| * |b| * cosθ 点乘又叫向量的内积、数量积,是一个向量和它在另一个向量上的投影的长度的乘积;是标量。
向量的叉乘:a x b
a x b = |a| * |b| * sinθ 向量积被定义为: 模长:(在这里θ表示两向量之间的夹角(共起点的前提下)(0° ≤ θ ≤ 180°),它位于这两个矢量所定义的平面上。)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<functional>
#include<deque>
#include<cmath>
using namespace std;
const int N = 1E5 + 10;
const double eps = 0.1;
int arr[N];
struct node {
double x;
double y;
}pre[30];
double cross(node a,node b,node c) {
return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);
}
double display(node a, node b) {
return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
}
int main() {
int t;
scanf("%d", &t);
while (t--) {
bool flag=false;
for (int i = 1; i <= 20; i++) {
scanf("%lf %lf", &pre[i].x, &pre[i].y);
}
pre[21] = pre[1];
pre[22] = pre[2];
for (int i = 1; i <= 20; i++) {
if (fabs(display(pre[i],pre[i+1])-9) <= eps) {
if ((fabs(display(pre[i+1], pre[i+2])-8)<=eps&&
cross(pre[i],pre[i+1],pre[i+2])>0)||(fabs(display(pre[i+1],pre[i+2])-6)<=eps
&&cross(pre[i],pre[i+1],pre[i+2])<0))
{
flag = true;
break;
}
}
}
if (flag) printf("right\n");
else printf("left\n");
}
}