A. Where do I Turn?
来源:互联网 发布:魔兽月卡 知乎 编辑:程序博客网 时间:2024/05/24 03:20
Trouble came from the overseas lands: a three-headed dragon Gorynych arrived. The dragon settled at point C and began to terrorize the residents of the surrounding villages.
A brave hero decided to put an end to the dragon. He moved from point A to fight with Gorynych. The hero rode from point A along a straight road and met point B on his way. The hero knows that in this land for every pair of roads it is true that they are either parallel to each other, or lie on a straight line, or are perpendicular to each other. He also knows well that points B and C are connected by a road. So the hero must either turn 90 degrees to the left or continue riding straight ahead or turn 90 degrees to the right. But he forgot where the point C is located.
Fortunately, a Brave Falcon flew right by. It can see all three points from the sky. The hero asked him what way to go to get to the dragon's lair.
If you have not got it, you are the falcon. Help the hero and tell him how to get him to point C: turn left, go straight or turn right.
At this moment the hero is believed to stand at point B, turning his back to point A.
The first input line contains two space-separated integers xa, ya (|xa|, |ya| ≤ 109) — the coordinates of point A. The second line contains the coordinates of point B in the same form, the third line contains the coordinates of point C.
It is guaranteed that all points are pairwise different. It is also guaranteed that either point B lies on segment AC, or angle ABC is right.
Print a single line. If a hero must turn left, print "LEFT" (without the quotes); If he must go straight ahead, print "TOWARDS" (without the quotes); if he should turn right, print "RIGHT" (without the quotes).
0 00 11 1
RIGHT
-1 -1-3 -3-4 -4
TOWARDS
-4 -6-3 -7-2 -6
LEFT
The picture to the first sample:
The red color shows points A, B and C. The blue arrow shows the hero's direction. The green color shows the hero's trajectory.
The picture to the second sample:
解题说明:题目的描述很长,讲的是一个勇士去杀龙的故事。不过翻译过来其实是一道平面几何题目,给出平面上三个点A,B,C. 现在已经从A点到了B点,现在要去C点,问方向是怎么样的。做法就是判断AB这条线的斜率与BC这条线的斜率关系,至于求斜率用两个点的坐标即可。
#include <iostream>#include<algorithm>#include<cstdio>#include<cmath>#include<cstring>#include<cstdlib>using namespace std;int main(){long long x1,x2,x3,y1,y2,y3;scanf("%I64d%I64d",&x1,&y1);scanf("%I64d%I64d",&x2,&y2);scanf("%I64d%I64d",&x3,&y3);if((y2-y1)*(x3-x2)==(y3-y2)*(x2-x1)){printf("TOWARDS\n"); }else if((x3-x2)*(y2-y1)-(x2-x1)*(y3-y2)>0){ printf("RIGHT\n"); }else {printf("LEFT\n");}return 0;}
- A. Where do I Turn?
- CodeForces 227A Where do I Turn?
- where do I turn?
- codeforces #140 dv2 A where do I turn
- Codeforces 227A Where do I Turn?(代数)
- Codeforces Round #140 (Div. 2) A. Where do I Turn?
- where do i belong
- Where do I belong
- Where Do I LOOK Now?
- Bonfire: Where do I belong
- Where do I store my custom configuration for a BizTalk solution
- FreeCodeCamp学习--Where do I belong
- I would like to learn PFC. Where Do I start?
- I want to learn Android Development, where do I start?
- Where do I find more information about XML?
- Where do I belong 重点:arr.sort(compareFunction)
- How do you turn a Mongoose document into a plain object?
- How do I create a MEX file
- 设计模式之模板方法模式
- 刷新 service
- 字如其人——免费的爱情测谎仪
- JQuery 1.10.2源码分析学习4(转载)
- SQL server 中更新表中的text、ntext或image字段信息
- A. Where do I Turn?
- 检测文件的真实类型
- Java学习笔记——通过异常处理错误
- 1765. 笨小猴
- 无法解析的外部符号 _Direct3DCreate9@4
- 使用Unity 实现依赖注入
- iframe自适应问题
- 漫谈软硬件的开发(转载)
- Android真机调试不打印日志解决