where do I turn?

本文介绍了一道CodeForces上的题目,通过向量的叉乘判断英雄从A点到B点后应转向的方向。利用叉乘的几何意义,仅需计算Z坐标确定方向。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原题链接:

http://codeforces.com/problemset/problem/227/A

题目大意:英雄从A点出发,到达B点,然后判断到达B点后应该左转(LEFT),右转(RIGHT),还是直接(TOWARDS)到达。

解题思路:这是一个判断C点在向量AB左边,右边还是直接在向量AB上面的问题。可以通过向量的叉乘来解题。叉乘的定义如下(摘自博客http://blog.youkuaiyun.com/dcrmg/article/details/52416832):

叉乘公式

两个向量的叉乘,又叫向量积、外积、叉积,叉乘的运算结果是一个向量而不是一个标量。并且两个向量的叉积与这两个向量组成的坐标平面垂直。

对于向量a和向量b:

a和b的叉乘公式为:

其中:

根据i、j、k间关系,有:

叉乘几何意义

在三维几何中,向量a和向量b的叉乘结果是一个向量,更为熟知的叫法是法向量,该向量垂直于a和b向量构成的平面。

在3D图像学中,叉乘的概念非常有用,可以通过两个向量的叉乘,生成第三个垂直于a,b的法向量,从而构建X、Y、Z坐标系。

在此题目中向量AB与AC都位于XY轴所在的平面上,所以仅仅只要看生成后的Z的坐标,用向量AB叉乘向量AC,然后判断Z值的正负,及AB向量为(x1,y1),AC向量为(x2,y2)的话,只需要计算出上图中x1*y2-x2*y1的值的正负即可。代码如下:

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main() {
	double a[3][2];
	for (int i=0; i<3; i++) {
		cin>>a[i][0]>>a[i][1];
	}
	double x1=a[1][0]-a[0][0];
	double y1=a[1][1]-a[0][1];
	double x2=a[2][0]-a[0][0];
	double y2=a[2][1]-a[0][1];
	double result = x1*y2-x2*y1;
	if (result == 0) cout<<"TOWARDS"<<endl;
	else if (result > 0) cout<<"LEFT"<<endl;
	else cout<<"RIGHT"<<endl;
	return 0;
}


Dear Friend ; Especially for you - this amazing announcement . This is a one time mailing there is no need to request removal if you won't want any more ! This mail is being sent in compliance with Senate bill 2316 , Title 1 ; Section 303 ! This is not a get rich scheme . Why work for somebody else when you can become rich in 77 months . Have you ever noticed society seems to be moving faster and faster and more people than ever are surfing the web ! Well, now is your chance to capitalize on this ! We will help you turn your business into an E-BUSINESS and sell more . You can begin at absolutely no cost to you . But don't believe us . Ms Ames who resides in Indiana tried us and says "Now I'm rich, Rich, RICH" . We are licensed to operate in all states . If not for you then for your LOVED ONES - act now ! Sign up a friend and you'll get a discount of 30% ! Thank-you for your serious consideration of our offer . Dear Friend ; Especially for you - this cutting-edge intelligence . If you are not interested in our publications and wish to be removed from our lists, simply do NOT respond and ignore this mail . This mail is being sent in compliance with Senate bill 1620 ; Title 3 , Section 309 . This is not multi-level marketing . Why work for somebody else when you can become rich in 48 days . Have you ever noticed the baby boomers are more demanding than their parents and nobody is getting any younger ! Well, now is your chance to capitalize on this . We will help you SELL MORE & decrease perceived waiting time by 140% . You can begin at absolutely no cost to you ! But don't believe us . Mrs Ames of California tried us and says "Now I'm rich, Rich, RICH" . We assure you that we operate within all applicable laws ! We implore you - act now ! Sign up a friend and you'll get a discount of 60% . God Bless ! Dear Friend ; Thank-you for your interest in our briefing . We will comply with all removal requests ! This mail is being sent in compliance with Senate bill 2716 , Title 3 ; Section 306 . This is a ligitimate business proposal ! Why work for somebody else when you can become rich as few as 26 months ! Have you ever noticed people will do almost anything to avoid mailing their bills & more people than ever are surfing the web . Well, now is your chance to capitalize on this ! We will help you decrease perceived waiting time by 180% and increase customer response by 100% ! You are guaranteed to succeed because we take all the risk . But don't believe us . Mrs Ames who resides in Idaho tried us and says "My only problem now is where to park all my cars" . We are licensed to operate in all states . We BESEECH you - act now . Sign up a friend and your friend will be rich too ! Warmest regards . 找flag
最新发布
05-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值