牛客(多校3):Operation Love

牛客(多校3):Operation Love_第1张图片
牛客(多校3):Operation Love_第2张图片
示例:
输入

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

示例2:
输入
链接:https://ac.nowcoder.com/acm/contest/5668/C
来源:牛客网

1
19.471068 -6.709056
13.814214 -1.052201
13.107107 -1.759308
15.228427 -3.880629
14.521320 -4.587735
10.985786 -1.052201
10.278680 -1.759308
13.814214 -5.294842
13.107107 -6.001949
9.571573 -2.466415
8.864466 -3.173522
12.400000 -6.709056
11.692893 -7.416162
8.157359 -3.880629
7.450253 -4.587735
12.400000 -9.537483
11.692893 -10.244590
9.571573 -8.123269
8.864466 -8.830376
13.107107 -13.073017

输出

right

牛客(多校3):Operation Love_第3张图片
代码:

#pragma GCC optimize(2)//编辑优化
#pragma GCC optimize(3)//编辑优化
#include
using namespace std;
struct node{double x,y;}a[22];
double eps=0.00001;
double le(node x,node y){return sqrt((x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y));}
double cj(node a,node b,node c){return (a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x);}
int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        bool f=0;
        for(int i=0;i<20;i++)
            scanf("%lf%lf",&a[i].x,&a[i].y);
        for(int i=0;i<20;i++)
            if(fabs(le(a[i],a[(i+1)%20])-9.0)<eps)
            {
                node x=a[i],y=a[(i+1)%20],z=a[(i+2)%20];
                if(cj(x,y,z)>0&&fabs(le(y,z)-6)<eps||cj(x,y,z)<0&&fabs(le(y,z)-8)<eps)
                    f=1;
                break;
            }
        if(f)printf("left\n");
        else printf("right\n");
    }
}

你可能感兴趣的:(ACM)