题意:给你四个点,判断能否先依次通过A,B两点,然后再在某个地方只进行一次直角转弯再一次经过C,D两点;

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const double eps=1e-12;
struct Point{
double x,y,z;
void read(){
scanf("%lf %lf %lf",&x,&y,&z);
};
}; int dcmp(double a)
{
if(fabs(a)<eps) return 0;
return a>0?1:-1;
} double Dot(Point a,Point b)
{
return a.x*b.x+a.y*b.y+a.z*b.z;
} Point cross(Point a,Point b)
{
return Point{a.y*b.z-a.z*b.y,a.z*b.x-a.x*b.z,a.x*b.y-a.y*b.x};
}
Point operator-(Point a,Point b)
{
return Point{a.x-b.x,a.y-b.y,a.z-b.z};
}
double dis(Point a,Point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z));
}
int main()
{
Point a,b,c,d;
a.read();b.read();c.read();d.read();
Point ab=b-a,cd=d-c,ca=a-c,cb=b-c,ad=d-a,ac=c-a;
if(Dot(ab,cd)!=0||Dot(ab,cross(ad,cd))!=0) {printf("Invalid\n");return 0;}
double x1=Dot(cross(cd,ca),cross(cd,cb)),
x2=Dot(cross(ab,ac),cross(ab,ad));
if(dcmp(x1)>=0&&dcmp(x2)>=0)
{
if(dis(b,c)>=dis(a,c)||dis(c,b)>=dis(d,b)) printf("Invalid\n");
else printf("Valid\n");
}
else printf("Invalid\n");
return 0;
}

分析:这道题涉及到了几个知识点:

1.判断四点是否共面

if(Dot(ab,cross(ad,cd))!=0)

代码如上,假设平面有A,B,C,D四点,那么先求出a,c,d三点确定的平面的一个法向量方向的向量,

然后再判断向量ab是否垂直该向量。

2.因为即使ab与cd垂直且共面,也不一定就满足条件,因为可能是ab与cd规范相交(不在端点处

相交),那么这个时候就需要进行跨立实验判断是否两条线段都只在对方的同一侧了

3.即使二满足了,也不一定是正确的,因为题目要求的是一次经过A,B,C,D四点,那么还要判断下

四个点的相对位置关系,不过因为已经确定了垂直关系,那么这个时候只需要比较下点之间的距离

就可以确定了

J - Space Invader

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

Winter in Yekaterinburg is the longest time of the year. And everyone spends long winter evenings in his own way. For example, Eugene creates computer games in the evenings. His current game has a very simple game play — user controls a spaceship flying in 3D space. To test the mechanics of the movement of his spaceship Eugene wants to solve the following problem: can his spaceship, moving in a straight line, fly through the points A and B, then make a turn at 90°, and then fly through the points C and D, continuing to move in a straight line. The points ABCD should be visited by the spaceship in just that order, the turning point may coincide with the point B or the point C. The spaceship should be considered as a material point.

Input

There are four lines, each containing integers xiyizi that are the coordinates of the points ABCD respectively(−10 6 ≤ xiyizi ≤ 10 6) . All points are pairwise different.

Output

If the spaceship can fly through the data points, output “Valid”, otherwise output “Invalid”.

Sample Input

input output
-2 0 0
-1 0 0
0 1 0
0 2 0
Valid
 

暑假集训#2 div1 J 四点直角 J - Space Invader 四点共面+跨立实验的更多相关文章

  1. 暑假集训 #2 div1 I - Lada Priora 精度处理

    I - Lada Priora Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Sub ...

  2. 2015UESTC 暑假集训总结

    day1: 考微观经济学去了…… day2: 一开始就看了看一道题目最短的B题,拍了半小时交了上去wa了 感觉自己一定是自己想错了,于是去拍大家都过的A题,十分钟拍完交上去就A了 然后B题写了一发暴力 ...

  3. STL 入门 (17 暑假集训第一周)

    快速全排列的函数 头文件<algorithm> next_permutation(a,a+n) ---------------------------------------------- ...

  4. 暑假集训Day2 互不侵犯(状压dp)

    这又是个状压dp (大型自闭现场) 题目大意: 在N*N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上下左右,以及左上左下右上右下八个方向上附近的各一个格子,共8个格子. ...

  5. 暑假集训Day1 整数划分

    题目大意: 如何把一个正整数N(N长度<20)划分为M(M>=1)个部分,使这M个部分的乘积最大.N.M从键盘输入,输出最大值及一种划分方式. 输入格式: 第一行一个正整数T(T<= ...

  6. 暑假集训(2)第七弹 -----今年暑假不AC(hdu2037)

    J - 今年暑假不AC Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     64 ...

  7. 暑假集训——cf热身赛部分题有感加其题解

    刚刚开始集训,集训队队长暂时还没有拉专题,而是拉了部分codeforces上过题人数在2000左右的题组成了一场热身赛(其实就是一场练习),花了一天时间终于把它刷完了,其中很多题让我学到了很多骚操作, ...

  8. 2016huasacm暑假集训训练五 H - Coins

    题目链接:http://acm.hust.edu.cn/vjudge/contest/126708#problem/H 题意:A有一大堆的硬币,他觉得太重了,想花掉硬币去坐的士:的士司机可以不找零,但 ...

  9. 2016huasacm暑假集训训练五 G - 湫湫系列故事——减肥记I

    题目链接:http://acm.hust.edu.cn/vjudge/contest/126708#problem/G 这是一个01背包的模板题 AC代码: #include<stdio.h&g ...

随机推荐

  1. Shell初学(七)linux账户管理/群组管理

    [1]新建用户 用户相关文件:/etc/passwd  /etc/shadow useradd useradd的默认预设 [2]设置密码 passwd 常见修改密码使用技巧: echo "1 ...

  2. Vue 2019开发者图谱

    作为 Vue 的初学者,您或许已经听过很多关于它的专业术语了,例如:单页面应用程序.异步组件.服务器端呈现等,您可能还听过和Vue经常一起被提到的工具和库,如Vuex.Webpack.Vue CLI和 ...

  3. Oracle 获取当前日期是月的第几周

    函数FUNC_GET_WEEKOFMONTH: IW 是年的自然周: WW是年的第一天起开始算7天为一周 FUNCTION FUNC_GET_WEEKOFMONTH (V_PSD DATE) RETU ...

  4. Java中创建的对象多了,必然影响内存和性能

    1, Java中创建的对象多了,必然影响内存和性能,所以对象的创建越少越好,最后还要记得销毁.

  5. Codeforces 1229C. Konrad and Company Evaluation

    传送门 首先考虑如何算出答案,考虑枚举中间那个点,显然每个点作为中间的点的次数为入度乘出度 所以答案就是每个点的入度乘出度之和 然后每个点开一个 $vector$ 维护从它出去的点数,每次修改的时候直 ...

  6. MyBatis的foreach查询(List、Array、Map)

    mybatis 中 foreach collection的三种用法 foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合. foreach元素的属性主要有 item,index ...

  7. Git复习(八)之快速理解Git结构

      git pull:拉取远程服务器最新代码到本地(会自动merge) git add:将本地代码添加到暂存区 git commit:将暂存区的所有内容提交到当前分支(git会自动为我们创建第一个分支 ...

  8. U盘重装系统

    一.准备工作 (1)8G以上空间的U盘一个: (2)将U盘制作好启动工具: 1.下载启动工具制作软件(常用的有:大白菜.电脑店.老毛桃.快启动等等一系列软件,直接百度这些软件的名称,或者百度U盘启动制 ...

  9. Linux Exploit系列之四 使用return-to-libc绕过NX bit

    使用return-to-libc绕过NX bit 原文地址:https://bbs.pediy.com/thread-216956.htm 这篇讲解的比较好,主要的问题是获得system地址和exit ...

  10. dedecms 列表标签 去斜杠 去两边空格

    首先:将 include/arc.listview.class.php 文件的第53行: $this->Fields['title'] = ereg_replace("[<> ...