2020牛客多校 第三场 C Operation Love 题解(叉积)

题目链接

题目大意

在这里插入图片描述
给你2个爪子,左爪和右爪,相互对称,给你右爪的图,然后给你20个连续的点(可顺可逆)要你判断是右爪还是左爪

题目思路

发现叉积可以应用到计算几何上,叉积可以确定一些相对位置,找最长边的那两个点,和挨着它的短的那条边的点,总共三个点,判断其叉积正负即可。注意一定要保证这三个点,每次顺序都一样!

叉积的其他作用

1:确定三角形的面积,叉积相乘除以2

2:已知直线上的两点s、e,可以求出ax+by+c=0的参数
a = s.y-e.y;
b = e.x-s.x;
c = s×e;

还有一些性质可以看这个博客:链接

代码

#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define debug printf("I am here\n");
using namespace std;
typedef long long ll;
const int maxn=30+5,mod=2147493647,inf=0x3f3f3f3f;
const double eps=1e-10;
int t;
double x[maxn],y[maxn];
double cal(double x1,double y1,double x2,double y2){
    return (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
}
int main(){
    scanf("%d",&t);
    while(t--){
        double  ma=-1;
        int pos1,pos2,l,mid,r;
        for(int i=1;i<=20;i++){
            scanf("%lf%lf",&x[i],&y[i]);
        }
        x[0]=x[20],y[0]=y[20];
        x[21]=x[1],y[21]=y[1];
        x[22]=x[2],y[22]=y[2];
        for(int i=1;i<=20;i++){
            double len=cal(x[i],y[i],x[i+1],y[i+1]);
            if(len>ma){
                ma=len;
                pos1=i,pos2=i+1;
            }
        }
        if(cal(x[pos1],y[pos1],x[pos1-1],y[pos1-1])<cal(x[pos2],y[pos2],x[pos2+1],y[pos2+1])){
            l=pos1-1,mid=pos1,r=pos2;
        }else{
            l=pos2+1,mid=pos2,r=pos1;
        }
        if((x[r]-x[mid])*(y[l]-y[mid])-(x[l]-x[mid])*(y[r]-y[mid])<0){
            printf("left\n");
        }else{
            printf("right\n");
        }
    }
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值