K - Cross Spider
Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87794#problem/K

Description

The Bytean cross spider (Araneida baitoida) is known to have an amazing ability. Namely, it can instantly build an arbitrarily large spiderweb as long as it is contained in a single plane. This ability gives the spider an opportunity to use a fancy hunting strategy. It does not need to wait until a fly is caught in an already built spiderweb; if only the spider knows the current position of a fly, it can instantly build a spiderweb to catch the fly. A cross spider has just spotted n flies in Byteasar’s garden. Each fly is flying still in some point of a 3D space. The spider is wondering if it can catch all the flies with a single spiderweb. Write a program that answers the spider’s question.

Input

The first line of the input contains an integer n (1 ¬ n ¬ 100 000). The following n lines contain a description of the flies in a 3D space: the i-th line contains three integers xi , yi , zi (−1 000 000 ¬ xi ; yi ; zi ¬ 1 000 000) giving the coordinates of the i-th fly (a point in a 3-dimensional Euclidean space). No two flies are located in the same point.

Output

Your program should output a single word TAK (i.e., yes in Polish) if the spider can catch all the flies with a single spiderweb. Otherwise your program should output the word NIE (no in Polish).

Sample Input

4 0 0 0 -1 0 -100 100 0 231 5 0 15

Sample Output

TAK

HINT

题意

一个三维空间,给n个点,问着n个点是否在同一个平面上

题解

首先先找到不在同一条直线上的三个点,做法向量,然后我们再枚举任意两个点,如果这两个点是和法向量垂直的话,就说明在一个平面上

代码:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <string>
#include <ctime>
#include <list>
#include <bitset>
typedef unsigned char byte;
#define pb push_back
#define input_fast std::ios::sync_with_stdio(false);std::cin.tie(0)
#define local freopen("in.txt","r",stdin)
#define pi acos(-1) using namespace std; typedef struct point
{
long long x , y , z;
}; const int maxn = 1e5 + ;
const double eps = 1e-;
int n ;
point A[maxn];
point vi; bool judge(point a,point b)
{
return a.x * b.y == b.x * a.y && a.y*b.z == b.y*a.z && a.x * b.z == a.z*b.x;
} int main(int argc,char *argv[])
{
scanf("%d",&n);
for(int i = ; i < n ; ++ i) scanf("%I64d%I64d%I64d",&A[i].x,&A[i].y,&A[i].z);
if (n <= )
{
printf("TAK\n");
return ;
}
else
{
int ok = ;
for(int i = ; i < n ; ++ i)
{
int a = i ;
int b = (i+) % n;
int c = (i+) % n;
point vi1 , vi2;
vi1.x = A[b].x - A[a].x;
vi1.y = A[b].y - A[a].y;
vi1.z = A[b].z - A[a].z;
vi2.x = A[c].x - A[b].x;
vi2.y = A[c].y - A[b].y;
vi2.z = A[c].z - A[b].z;
if (judge(vi1,vi2)) continue;
else
{
vi.x = vi1.y*vi2.z - vi2.y*vi1.z;
vi.y = vi2.x*vi1.z - vi1.x*vi2.z;
vi.z = vi1.x*vi2.y - vi1.y*vi2.x;
ok = ;
break;
}
}
if (ok)
{
printf("TAK\n");
return ;
}
else
{
ok = ;
for(int i = ; i < n ; ++ i)
{
int a = i ;
int b = (i+) % n;
point tx;
tx.x = A[b].x - A[a].x;
tx.y = A[b].y - A[a].y;
tx.z = A[b].z - A[a].z;
if (vi.x * tx.x + vi.y * tx.y + vi.z * tx.z != )
{
ok = ;
break;
}
}
}
if (ok) printf("TAK\n");
else printf("NIE\n");
return ;
}
return ;
}

Codeforces Gym 100523K K - Cross Spider 计算几何,判断是否n点共面的更多相关文章

  1. Codeforces Gym 100187K K. Perpetuum Mobile 构造

    K. Perpetuum Mobile Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/pro ...

  2. codeforces gym 100971 K Palindromization 思路

    题目链接:http://codeforces.com/gym/100971/problem/K K. Palindromization time limit per test 2.0 s memory ...

  3. Ampzz 2011 Cross Spider 计算几何

    原题链接:http://codeforces.com/gym/100523/attachments/download/2798/20142015-ct-s02e07-codeforces-traini ...

  4. Codeforces Gym 101505C : Cable Connection (计算几何)

    题目链接 题意:给出第一象限的N个点,存在一直线x/a+y/b=1(a>0,y>0)使得所有点都在这条直线下面,求 min{sqrt(a^2+b^2)} 显然,这样的直线必然经过这N个点中 ...

  5. codeforces gym 100357 K (表达式 模拟)

    题目大意 将一个含有+,-,^,()的表达式按照运算顺序转换成树状的形式. 解题分析 用递归的方式来处理表达式,首先直接去掉两边的括号(如果不止一对全部去光),然后找出不在括号内且优先级最低的符号.如 ...

  6. Codeforces Gym 100851 K King's Inspection ( 哈密顿回路 && 模拟 )

    题目链接 题意 : 给出 N 个点(最多 1e6 )和 M 条边 (最多 N + 20 条 )要你输出一条从 1 开始回到 1 的哈密顿回路路径,不存在则输出 " There is no r ...

  7. codeforces gym 101164 K Cutting 字符串hash

    题意:给你两个字符串a,b,不区分大小写,将b分成三段,重新拼接,问是否能得到A: 思路:暴力枚举两个断点,然后check的时候需要字符串hash,O(1)复杂度N*N: 题目链接:传送门 #prag ...

  8. Codeforces Gym 100286A. Aerodynamics 计算几何 求二维凸包面积

    Problem A. AerodynamicsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/co ...

  9. Codeforces Gym 101252D&&floyd判圈算法学习笔记

    一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...

随机推荐

  1. 项目管理工具:Maven使用方法总结

    阅读目录 一.概念 二.Maven安装 三.常用命令 四.生命周期 五.第一个Maven项目 六.POM文件 七.Maven库 八.参考资料 回到顶部 一.概念 Maven是一个项目管理和构建自动化工 ...

  2. 11g 重建EM 报ORA-20001: SYSMAN already exists

    今天在安装11g(11.1.0.7.0)数据库之后,通过emca -config dbcontrol db -repos create 命令手工创建em的时候报错,查看日志后发现有以下错误 CONFI ...

  3. [C++]cin读取回车键

    最近碰到一个问题,就是从控制台读取一组数,如: 12 23 34 56 若是使用 int data; while ( cin >> data ) {//...} 当回车后,不能有效转换到后 ...

  4. TextView字体和背景图片 设置透明度

    背景图片透明度设置  viewHolder.relative_layout.getBackground().setAlpha(225);     0  ---  225 ((TextView)tv). ...

  5. 《Python 学习手册4th》 第六章 动态类型简介

    ''' 时间: 9月5日 - 9月30日 要求: 1. 书本内容总结归纳,整理在博客园笔记上传 2. 完成所有课后习题 注:“#” 后加的是备注内容 (每天看42页内容,可以保证月底看完此书)“重点笔 ...

  6. Codeforces Round #363

    http://codeforces.com/contest/699 ALaunch of Collider 题意:n个球,每个球向左或右,速度都为1米每秒,问第一次碰撞的时间,否则输出-1 贪心最短时 ...

  7. 设计模式系列 1——StaticFactory(静态工厂),AbstractFactory(抽象工厂)

    本文出自 代码大湿 代码大湿 本系列持续更新,敬请关注. 1 静态工厂 静态工厂介绍: 静态工厂模式可以实现接口封装隔离的原则.在客户端只知接口而不知实现的时候可以使用静态工厂模式. 源码请点击我 角 ...

  8. HTML5每日一练之input新增加的六种时间类型应用

    今天介绍一下input在HTML5中新增加的时间类型的应用,与昨天的练习一样,如果在以下这几种输入框中输入的格式不正确,也是无法提交的. 注意:此种类型的input在Opera10+中效果为佳,Chr ...

  9. vim MiniBufExplorer 插件

    MiniBufExplorer安装好久了,但一直没怎么使用过. 今天查了下资料,作为一个备份. 当你只编辑一个buffer的时候MiniBufExplorer派不上用场, 当 你打开第二个buffer ...

  10. HDU 5753 Permutation Bo (推导 or 打表找规律)

    Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...