2020牛客暑期多校训练营(第三场)C Operation Love

题目链接

思路:

首先判断两个距离为9的点,就是手掌底部的点,这个距离是唯一的,然后判断手掌的大拇指,就是离底部任意两个点其中一个距离为6的点,这个距离也是惟一的,最后判断这三个点之间的关系与朝向即可,注意,因为判断点会有开方,会有精度丢失,所以我们判断的时候不能是1e-6,而是1e-3.

代码:

#include
using namespace std;
//#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N=2e6+7;
const double eps=1e-8;
const int mod=1e9+7;
const int inf=0x7fffffff;
const double pi=3.1415926535;
using namespace std;
double solve(double a,double b,double x,double y)
{
    double sum=(a-x)*(a-x)+(b-y)*(b-y);
}
signed main()
{
    IOS;
    int t;
    cin>>t;
    while(t--)
    {
        double dix1,diy1,dix2,diy2,x1,y1,x2,y2,x3,y3;
        double x[21],y[21];
        for(int i=1;i<=20;i++)
        {
            cin>>x[i]>>y[i];
        }
        for(int i=1;i<=20;i++)
        {
            for(int j=1;j<=20;j++)
            {
                double num=solve(x[i],y[i],x[j],y[j]);
                if(fabs(num-81)<eps)
                {
                    dix1=x[i];
                    diy1=y[i];
                    dix2=x[j];
                    diy2=y[j];
                    break;
                }
            }
        }
        for(int i=1;i<=20;i++)
        {
            double num=solve(dix1,diy1,x[i],y[i]);
            if(fabs(num-36)<eps)
            {
                x1=x[i];
                y1=y[i];
                x2=dix1;
                y2=diy1;
                x3=dix2;
                y3=diy2;
                break;
            }
        }
        for(int i=1;i<=20;i++)
        {
            double num=solve(dix2,diy2,x[i],y[i]);
            if(fabs(num-36)<eps)
            {
                x1=x[i];
                y1=y[i];
                x2=dix2;
                y2=diy2;
                x3=dix1;
                y3=diy1;
                break;
            }
        }
        if(x1==x2)
        {
            if(y1>y2)
            {
                if(x3>x1)
                {
                    cout<<"right"<<endl;
                }
                else
                {
                    cout<<"left"<<endl;
                }
            }
            else
            {
                if(x3>x1)
                {
                    cout<<"left"<<endl;
                }
                else
                {
                    cout<<"right"<<endl;
                }
            }
        }
        else if(x1>x2)
        {
            if(y3>y2)
            {
                cout<<"left"<<endl;
            }
            else
            {
                cout<<"right"<<endl;
            }
        }
        else
        {
            if(y3>y2)
            {
                cout<<"right"<<endl;
            }
            else
            {
                cout<<"left"<<endl;
            }
        }
        cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<" "<<x3<<" "<<y3<<endl;
    }
    return 0;
}

你可能感兴趣的:(思维)