zoukankan      html  css  js  c++  java
  • 牛客第三场_C_Operation Love

    题意

    给定一个手掌的边界点(20个),你需要判断这是左手还是右手;给定的手掌可能是斜的而且大小也不一定
    

    思路

    找到手掌中最长的那一条线段,然后判断题目给出的点事顺时针还是逆时针,然后用最长的线段和右侧一
    条线段的比例来判断究竟是左手还是右手,(记得控制精度,因为给定的x,y精确到1e-6,所以eps直接取1e-6)
    

    代码

    #pragma GCC optimize(2)
    #include<unordered_map>
    #include<algorithm>
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<string>
    #include<vector>
    #include<queue>
    #include<stack>
    #include<cmath>
    #include<map>
    #include<set>
    #define Buff ios::sync_with_stdio(false)
    #define rush() int Case = 0; int T; cin >> T;  while(T--)
    #define rep(i, a, b) for(int i = a; i <= b; i ++)
    #define per(i, a, b) for(int i = a; i >= b; i --)
    #define reps(i, a, b) for(int i = a; b; i ++)
    #define clc(a, b) memset(a, b, sizeof(a))
    #define Buff ios::sync_with_stdio(false)
    #define readl(a) scanf("%lld", &a)
    #define readd(a) scanf("%lf", &a)
    #define readc(a) scanf("%c", &a)
    #define reads(a) scanf("%s", a)
    #define read(a) scanf("%d", &a)
    #define lowbit(n) (n&(-n))
    #define pb push_back
    #define lson rt<<1
    #define rson rt<<1|1
    #define ls lson, l, mid
    #define rs rson, mid+1, r
    #define y second
    #define x first
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair<int, int>PII;
    const int mod = 1e9+7;
    const double eps = 1e-6;
    const int N = 1e6+7;
    const double PI = acos(-1);
    int dcmp(double x)
    {
        if(fabs(x) < eps)   return 0;
        else                return x < 0 ? -1 : 1;
    }
    struct Point
    {
        double x;
        double y;
        Point(double x=0, double y=0):x(x), y(y) {}
    };
    typedef Point Vector;
    double operator * (const Vector & v, const Vector & w)  {return v.x * w.x + v.y * w.y;}
    double operator ^ (const Vector & v, const Vector & w)  {return v.x * w.y - v.y * w.x;}
    double length(Vector v)                                 {return sqrt(v * v);}
    Vector operator - (const Vector & v, const Vector & w)  {return Vector(v.x - w.x, v.y - w.y);}
    void print(string s, Point t)
    {
        cout << s <<": ("<< t.x <<" "<< t.y <<")" <<endl;
    }
    Point p[30];
    int main()
    {
        rush()
        {
            for(int i = 0; i < 20; i ++)
            {
                double x, y;
                cin >> x >> y;
                p[i] = {x, y};
            }
            double len = 0.0;
            int pos = 0;
            for(int i = 0; i < 20; i ++)
            {
                Vector v = p[i]-p[(i+1)%20];
                if(length(v) > len)
                {
                    len = length(p[i]-p[(i+1)%20]);
                    pos = i;
                }
            }
            Point a = p[pos], b = p[(pos+1)%20], c = p[(pos+2)%20];
            Vector v = b-a, w = c-a, u = c-b;
            double temp1 = 9.0/8.0, temp2 = 3.0/2.0;
            // cout <<"pos: "<< pos <<endl;
            // cout << length(v)/length(u) <<endl;
            if(dcmp(v^w) > 0)
            {
                // cout << "colock!" <<endl;
                double k = length(v)/length(u);
                if(!dcmp(k-temp1))
                {
                    puts("right");
                }
                else if(!dcmp(k-temp2))
                {
                    puts("left");
                }
            }
            else
            {
                // cout << "uncolock!" <<endl;
                double k = length(v)/length(u);
                if(!dcmp(k-temp2))
                {
                    puts("right");
                }
                else if(!dcmp(k-temp1))
                {
                    puts("left");
                }
            }
        }
        return 0;
    }
    
  • 相关阅读:
    利用CSS3中的clac()实现按照屏幕分辨率自适应宽度
    没有被广泛采用的box-sizing属性
    HTML5学习笔记(四):关于表格
    HTML5学习笔记(三):标识文本的语义元素
    浏览器内核及相关
    oracle,如何查看视图结构,获得视图中的字段名称、字段类型、字段长度等。
    存一个工作中常用的类
    将字符串序列化Object格式
    让你的博客不再单调 --博客园设置随机背景图片教程
    新的模板新的开始
  • 原文地址:https://www.cnblogs.com/Farrell-12138/p/14036437.html
Copyright © 2011-2022 走看看