题目大意:就是给你两个左右手的模型,下面给出这两只手通过平移变换之后坐标问你这只手是左手还是右手?[题目保证坐标是按照顺时针或者逆时针给出的]
解题思路:首先我们先观察一下这只右手:假如数据是按照逆时针给出的那么(1,6),(1,0),(10,0)这三个点构成的两条边就会依次出现因为这两条边的长度是6和9是独一无二的所以我们可以先特判一下数据给出的方向然后for循环一遍寻找这两条边
1.如果是逆时针并且找的到这两条边那么就是右手否则就是左手
2.如果是时针并且找的到这两条边那么就是左手否这就是右手
判断顺逆时针的模板:
#include<iostream>
using namespace std;
int x[35], y[35];
int main(){
int N;
cin >> N;
for (int i = 0; i < N; i++)
cin >> x[i] >> y[i];
int d = 0;
for (int i = 0; i < N - 1; i++)
d += -0.5 * (y[i + 1] + y[i]) * (x[i + 1] - x[i]);
if(d > 0)
cout << "counterclockwise"<< endl;//逆
else
cout << "clockwise" << endl;//顺
}
AC代码:eps>1e-5:否者会wa
#include <iostream>
#include <cstdio>
#include <stack>
#include <sstream>
#include <vector>
#include <map>
#include <cstring>
#include <deque>
#include <cmath>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <set>
#define mid ((l + r) >> 1)
#define Lson rt << 1, l , mid
#define Rson rt << 1|1, mid + 1, r
#define ms(a,al) memset(a,al,sizeof(a))
#define log2(a) log(a)/log(2)
#define _for(i,a,b) for( int i = (a); i < (b); ++i)
#define _rep(i,a,b) for( int i = (a); i <= (b); ++i)
#define for_(i,a,b) for( int i = (a); i >= (b); -- i)
#define rep_(i,a,b) for( int i = (a); i > (b); -- i)
#define lowbit(x) ((-x) & x)
#define IOS std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INF 0x3f3f3f3f
#define hash Hash
#define next Next
#define count Count
#define pb push_back
#define f first
#define s second
using namespace std;
const int N = 2e6+10, mod = 1e9 + 7;
const long double eps = 1e-5;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
template<typename T> void read(T &x)
{
x = 0;char ch = getchar();ll f = 1;
while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
template<typename T, typename... Args> void read(T &first, Args& ... args)
{
read(first);
read(args...);
}
struct Point//点或向量
{
double x, y;
Point() {}
Point( double x, double y) :x(x), y(y) {}
};
typedef Point Vector;
int dcmp( double x)//精度三态函数(>0,<0,=0)
{
if (fabs(x) < eps)return 0;
else if (x > 0)return 1;
return -1;
}
Vector operator + (Vector a, Vector b)//向量加法
{
return Vector(a.x + b.x, a.y + b.y);
}
Vector operator - (Vector a, Vector b)//向量减法
{
return Vector(a.x - b.x, a.y - b.y);
}
Vector operator * (Vector a, double p)//向量数乘
{
return Vector(a.x*p, a.y*p);
}
Vector operator / (Vector a, double p)//向量数除
{
return Vector(a.x / p, a.y / p);
}
double Distance(Point a, Point b)//两点间距离
{
return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
}
bool operator == (const Point &a, const Point &b)//向量相等
{
return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;
}
long double Cross(Vector a, Vector b)//外积
{
return a.x*b.x + a.y*b.y;
}
bool cmp1(Point a,Point b)
{
if(atan2(a.y,a.x)!=atan2(b.y,b.x))
return atan2(a.y,a.x)<atan2(b.y,b.x);
else return a.x<b.x;
}
Point a[22];
int main()
{
int T;
read(T);
while(T --)
{
for(int i = 0; i < 20; ++ i)
cin >> a[i].x >> a[i].y;
double s = 0;
bool flag = 1;
for(int i = 0; i < 19; ++ i)
s += -0.5 * (a[i + 1].y + a[i].y) * (a[i + 1].x - a[i].x);
s += -0.5 * (a[0].y + a[19].y) * (a[0].x - a[19].x);
if(s > 0) flag = 1;
else flag = 0;
int tmp = -1;
if(!flag)
{
for(int i = 0; i < 20; ++ i)
if(dcmp(Distance(a[(i-1+20)%20],a[i]) - 6.0) == 0 && dcmp(Distance(a[(i+1)%20],a[i]) - 9.0) == 0)
{
tmp = i;
puts("left");
break;
}
if(tmp == -1) puts("right");
}
else
{
for(int i = 0; i < 20; ++ i)
if(dcmp(Distance(a[(i-1+20)%20],a[i]) - 6.0) == 0 && dcmp(Distance(a[(i+1)%20],a[i]) - 9.0) == 0)
{
tmp = i;
puts("right");
break;
}
if(tmp == -1) puts("left");
}
}
return 0;
}