题意:给你四个点,判断能否先依次通过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. DBGridEh列宽自动适应内容的简单方法

    ///////Begin   Source      uses          Math;            function   DBGridRecordSize(mColumn:   TCo ...

  2. ASP.NET Core中使用Autofac进行属性注入

    一些无关紧要的废话: 作为一名双修程序员(自封的),喜欢那种使用Spring的注解形式进行依赖注入或者Unity的特性形式进行依赖注入,当然,形式大同小异,但结果都是一样的,通过属性进行依赖注入. A ...

  3. P1004方格取数

    这是提高组得一道动态规划题,也是学习y氏思考法的第一道题. 题意为给定一个矩阵,里面存有一些数,你从左上角开始走到右下角,另一个人从右下角开始走到左上角,使得两个人取数之和最大,当然一个数只可以取走一 ...

  4. 经典网络流题目模板(P3376 + P2756 + P3381 : 最大流 + 二分图匹配 + 最小费用最大流)

    题目来源 P3376 [模板]网络最大流 P2756 飞行员配对方案问题 P3381 [模板]最小费用最大流 最大流 最大流问题是网络流的经典类型之一,用处广泛,个人认为网络流问题最具特点的操作就是建 ...

  5. python-连接mysql实例

    import pymysql # 创建连接 conn = pymysql.connect(host='192.168.71.140', port=3306, user='root', passwd=' ...

  6. Redis原子计数器incr,防止并发请求

    转自:https://blog.csdn.net/Roy_70/article/details/78260826 一.前言在一些对高并发请求有限制的系统或者功能里,比如说秒杀活动,或者一些网站返回的当 ...

  7. sqlalchemy.exc.InternalError: (pymysql.err.InternalError) (1366, "Incorrect string value: '\\xE6\\xB1\\x89\\xE8\\xAF\\xAD...' for column 'className' at row 1") [SQL: INSERT INTO classmessage (`classId

    sqlalchemy.exc.InternalError: (pymysql.err.InternalError) (1366, "Incorrect string value: '\\xE ...

  8. 自己实现JDK动态代理

    实验的目录结构 1.JDK动态代理 先来一段jdk动态代理的demo,首先创建一个接口,Person public interface Person { public void eat(); } 实现 ...

  9. hive元数据库理解

    在hive2.1.1 里面一共有59张表 表1 VERSION ; version表存hive的版本信息,该表中数据只有一条,如果存在多条,会造成hive启动不起来. 表2  DBS select * ...

  10. 设置Windows静态IP+动态IP

    静态IP 设置以太网属性 进入IPv4属性 设置IPv4 动态IP 同上方法,只不过选成了自动