2020 牛客多校第三场 C Operation Love (叉积判断顺逆时针)
2020 牛客多校第三场 (叉积判断顺逆时针)
Operation Love
大意: 给出一个手型 , 每个手型都有 20 个点 ,手型有可能旋转后给出 , 但不会放大和缩小 . 手型点集有可能顺时针给出也可能逆时针给出 , 判断给出的是左手还是右手。
思路:图形只会旋转但是不会放大和缩小 , 这很重要 。我们可以用最长边作为基准边。先判断顺时针还是逆时针 ,根据基准边的下一个点在基准边的左右进行判断。而判断完顺逆时针就可以判断左右手 , 根据基准边下一条边长度判断即可。
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long
const int N = 2e6 + 10;
const int mod = 1e9 + 7;
typedef pair<int,int>PII;//--------------------------------------------------------------
const double eps = 1e-5;
const double pi = acos(-1);
inline double sqr(double x) {return x * x;} //平方
int sign(double x){if(fabs(x) < eps) return 0;if(x > 0) return 1;return -1;
}//符号
struct point{double x , y;point(){}point(double a , double b) : x(a) , y(b){}friend point operator + (const point &a , const point &b){return point(a.x + b.x , a.y + b.y);}friend point operator - (const point &a , const point &b){return point(a.x - b.x , a.y - b.y);}friend bool operator == (const point &a , const point &b){return !sign(a.x - b.x) && !sign(a.y - b.y);}friend point operator * (const point &a , const double &b){return point(a.x * b , a.y * b);}friend point operator * (const double &a , const point &b){return point(a * b.x , a * b.y);}friend point operator / (const point &a , const double &b){return point(a.x / b , a.y / b);}//向量模长 double norm(){ return sqrt(sqr(x) + sqr(y));}
}; double det(const point &a , const point &b){return a.x * b.y - a.y * b.x;
}//叉积 判断两点共线 double dot(const point &a , const point &b){return a.x * b.x + a.y * b.y;
}//点积double dist(const point &a , const point &b){return (a - b).norm();
}//两点距离point rotate_point(const point &a , const point &p , double A){double tx = p.x - a.x , ty = p.y - a.y;return point(a.x + tx * cos(A) - ty * sin(A) , a.y + tx * sin(A) + ty * cos(A));
}// p 点 绕 a 点逆时针旋转 A 弧度//大于 0 点在线左边
//等于 0 点在线上边
//小于 0 点在线右边
double toleft(point p , point a, point b) {point A = point(b.x - a.x , b.y - a.y); //向量abpoint B = point(p.x - a.x , p.y - a.y); //向量apreturn det(A , B);
}//--------------------------------------------------------------int t , n;
point p[50];
double x , y;inline int nex(int x){ return (x + 1) % n ; }
inline int pre(int x){ return (x - 1 + n) % n ; }signed main(){IOScin >> t;while(t --){n = 20;for(int i = 0 ; i < n ; i ++){cin >> x >> y;p[i] = {x , y};}int id = 0;for(int i = 0 ; i < n ; i ++) if(sign(dist(p[i] , p[nex(i)]) - 9.0) == 0) id = nex(i);if(sign(toleft(p[nex(id)] , p[pre(id)] , p[id])) == 1 && sign(dist(p[id] , p[nex(id)]) - 8.0) == 0 || sign(toleft(p[nex(id)] , p[pre(id)] , p[id])) == -1 && sign(dist(p[id] , p[nex(id)]) - 6.0) == 0){cout << "right\n";}else{cout << "left\n";}} return 0;
}
//freopen("文件名.in","r",stdin);
//freopen("文件名.out","w",stdout);