Codeforces Gym 100523K K - Cross Spider 计算几何,判断是否n点共面
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
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点共面的更多相关文章
- Codeforces Gym 100187K K. Perpetuum Mobile 构造
K. Perpetuum Mobile Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/pro ...
- codeforces gym 100971 K Palindromization 思路
题目链接:http://codeforces.com/gym/100971/problem/K K. Palindromization time limit per test 2.0 s memory ...
- Ampzz 2011 Cross Spider 计算几何
原题链接:http://codeforces.com/gym/100523/attachments/download/2798/20142015-ct-s02e07-codeforces-traini ...
- Codeforces Gym 101505C : Cable Connection (计算几何)
题目链接 题意:给出第一象限的N个点,存在一直线x/a+y/b=1(a>0,y>0)使得所有点都在这条直线下面,求 min{sqrt(a^2+b^2)} 显然,这样的直线必然经过这N个点中 ...
- codeforces gym 100357 K (表达式 模拟)
题目大意 将一个含有+,-,^,()的表达式按照运算顺序转换成树状的形式. 解题分析 用递归的方式来处理表达式,首先直接去掉两边的括号(如果不止一对全部去光),然后找出不在括号内且优先级最低的符号.如 ...
- Codeforces Gym 100851 K King's Inspection ( 哈密顿回路 && 模拟 )
题目链接 题意 : 给出 N 个点(最多 1e6 )和 M 条边 (最多 N + 20 条 )要你输出一条从 1 开始回到 1 的哈密顿回路路径,不存在则输出 " There is no r ...
- codeforces gym 101164 K Cutting 字符串hash
题意:给你两个字符串a,b,不区分大小写,将b分成三段,重新拼接,问是否能得到A: 思路:暴力枚举两个断点,然后check的时候需要字符串hash,O(1)复杂度N*N: 题目链接:传送门 #prag ...
- Codeforces Gym 100286A. Aerodynamics 计算几何 求二维凸包面积
Problem A. AerodynamicsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/co ...
- Codeforces Gym 101252D&&floyd判圈算法学习笔记
一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...
随机推荐
- 【转】 IOS中定时器NSTimer的开启与关闭
原文网址:http://blog.csdn.net/enuola/article/details/8099461 调用一次计时器方法: myTimer = [NSTimer scheduledTime ...
- 利用反射自动生成SQL语句(仿Linq)
转:http://www.cnblogs.com/the7stroke/archive/2012/04/22/2465597.html using System; using System.Colle ...
- ASIHttpRequest编译不通过
转:http://blog.sina.com.cn/s/blog_67a5e47201014tof.html Undefined symbols for architecture i386: &q ...
- 建立简单的VLAN通信
http://minitoo.blog.51cto.com/4201040/786011(转载) 在路由器上做单臂路由实现VLAN间路由,也就是设置子接口和封装协议. 实现环境如下图: 在交换机上建立 ...
- Ubuntu中、英文环境设置
改变ubuntu的中英文显示需要修改文件/etc/default/locale,具体设置过程为: 1.打开/etc/default/locale文件 #sudo vim /etc/default/lo ...
- 利用redis分布式锁的功能来实现定时器的分布式
文章来源于我的 iteye blog http://ak478288.iteye.com/blog/1898190 以前为部门内部开发过一个定时器程序,这个定时器很简单,就是配置quartz,来实现定 ...
- linux进程调度函数浅析(基于3.16-rc4)
众所周知,进程调度使用schedule()函数来完成,下面我们从分析该函数开始,代码如下(kernel/sched/core.c): asmlinkage __visible void __sched ...
- C# 引用类型的"祸害"
前端时间刚刚弄完一个项目,终于有时间来总结与回顾了. 项目需求:给用户发送邮件,邮件分为系统邮件和个人邮件,需要按时间.未读降序排列. 一开始以为,这是一个很简单的需求,给邮件建了一个对象: clas ...
- Hadoop-Map/Reduce实现实现倒排索引
先来简单介绍一下什么是文档倒排索引 倒排索引是文档检索系统中最常见的数据结构,被广泛应用在全文搜索引擎上.主要用来存储某个单词(或词组)在一个文档或者一组文档中的存储位置的映射,即提供了一种根据内容来 ...
- public, protected, private, internal, protected internal简析
public是可访问权限最高的,比如姓名,每个人都可以知道别人的姓名,这个不是什么秘密 protected的访问权限要低些,只有子类才可以访问得到父类的protected属性.就好像老子的财产只有儿子 ...