poj 2653 计算几何
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
struct point {
double x,y;
};
point be[],en[];
int ans[];
int res[]; double max(double a,double b){
return a>b?a:b;
}
double min(double a,double b){
return a<b?a:b;
} int inter(point a,point b,point c,point d){
if(min(a.x,b.x)>max(c.x,d.x)||min(a.y,b.y)>max(c.y,d.y)||min(c.x,d.x)>max(a.x,b.x)||min(c.y,d.y)>max(a.y,b.y))
return ;
double h,i,j,k;
h = (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x);
i = (d.x-a.x)*(b.y-a.y)-(d.y-a.y)*(b.x-a.x);
j = (a.x-c.x)*(d.y-c.y)-(a.y-c.y)*(d.x-c.x);
k = (b.x-c.x)*(d.y-c.y)-(b.y-c.y)*(d.x-c.x);
return h*i<&&j*k<;
}
int main()
{
int n;
while(scanf("%d",&n)==&&n){
for(int i=;i<n;i++)
cin>>be[i].x>>be[i].y>>en[i].x>>en[i].y;
memset(ans,,sizeof(ans));
memset(res,,sizeof(res));
for(int i=;i<n;i++){
for(int j=i+;j<n;j++){
if(inter(be[i],en[i],be[j],en[j])){
ans[i] =;
break;
}
}
}
int cnt =;
for(int i=;i<n;i++){
if(!ans[i])
res[cnt++] = i+;
}
printf("Top sticks: ");
for(int i=;i<cnt-;i++)
printf("%d, ",res[i]);
printf("%d.\n",res[cnt-]); }
return ;
}
poj 2653 计算几何的更多相关文章
- 线段相交 POJ 2653
// 线段相交 POJ 2653 // 思路:数据比较水,据说n^2也可以过 // 我是每次枚举线段,和最上面的线段比较 // O(n*m) // #include <bits/stdc++.h ...
- poj 2653 线段与线段相交
Pick-up sticks Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 11884 Accepted: 4499 D ...
- 计算几何--判断两条线段相交--poj 2653
Pick-up sticks Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 8862 Accepted: 3262 De ...
- 2018.07.03 POJ 2653 Pick-up sticks(简单计算几何)
Pick-up sticks Time Limit: 3000MS Memory Limit: 65536K Description Stan has n sticks of various leng ...
- poj 2653 (线段相交判断)
http://poj.org/problem?id=2653 Pick-up sticks Time Limit: 3000MS Memory Limit: 65536K Total Submis ...
- POJ 2653 - Pick-up sticks - [枚举+判断线段相交]
题目链接:http://poj.org/problem?id=2653 Time Limit: 3000MS Memory Limit: 65536K Description Stan has n s ...
- POJ 1556 计算几何+最短路
代码1: #include<iostream> #include<stdio.h> #include<string> #include<string.h> ...
- POJ 2653 Pick-up sticks
计算几何,判断线段相交 注意题目中的一句话:You may assume that there are no more than 1000 top sticks. 我认为是没有描述清楚的,如果不是每次 ...
- POJ 2954-Triangle(计算几何+皮克定理)
职务地址:POJ 2954 意甲冠军:三个顶点的三角形,给出,内部需求格点数. 思考:就像POJ 1265. #include <stdio.h> #include <math.h& ...
随机推荐
- Android中实现ListView圆角效果[转]
本文演示如何Android中实现ListView圆角效果. 无论是网站,还是APP,人们都爱看一些新颖的视图效果.直角看多了,就想看看圆角,这几年刮起了一阵阵的圆角设计风:CSS新标准纳入圆角元素,特 ...
- Unity3d 要点板书
WWW.unity3d.com.cn Unity Project unity的项目文件/专案 Scene unity的场景文件 Scene 场景视窗 Game 预览视窗 H... 物件视窗 Pro ...
- WCF:System.Security.Cryptography.CryptographicException: 密钥集不存在
WCF使用IIS部署时,使用x509证书验证,在创建证书并正确配置程序后,访问出现错误提示: System.Security.Cryptography.CryptographicException: ...
- Bootstrap学习之一起步
说起Bootstrap,第一次接触到这个名词的时候还是同事在做自适应页面技术分享会时了解到,在之后的项目中就逐渐应用了这个前端WEB CSS框架.
- C#Base64加密
using System;using System.Collections.Generic;using System.Text;using System.Security.Cryptography;u ...
- 页面的拼装配置Appache SSI
O(∩_∩)O哈哈哈~今天又遇到了一个好东西,记录一下下哈~ 一个网站,有些页面的头部跟尾部是相同的,还在为总是复制,为错了一个小小点而需要改好多个页面烦恼吗?现在我知道怎么来偷懒了! 1.首先找到c ...
- [LeetCode]题解(python):143-Reorder List
题目来源: https://leetcode.com/problems/reorder-list/ 题意分析: 给定一个链表L:L0→L1→…→Ln-1→Ln,改变链表的排序为: L0→Ln→L1→L ...
- 关于BFC
参考 http://www.html-js.com/article/1866(很棒! 还有栗子) http://www.cnblogs.com/lhb25/p/inside-block-format ...
- 常见iis错误之一
1.win7配置iis 出现:HTTP 错误 403.14 - Forbidden 打开 IIS 管理器. 在“功能”视图中,双击“目录浏览”. 在“目录浏览”页上,在“操作”窗格中单击“启用”. 确 ...
- WinAPI: GetVolumeInformation - 读取文件系统信息
//声明: GetVolumeInformation( lpRootPathName: PChar; {磁盘驱动器代码字符串} lpVolumeNameBuffer: ...