hdu 1147 pick up sticks 几何问题线段相交
来源:互联网 发布:安装linux u盘坏了 编辑:程序博客网 时间:2024/06/05 11:51
Pick-up sticks
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3427 Accepted Submission(s): 1280
Problem Description
Stan has n sticks of various length. He throws them one at a time on the floor in a random way. After finishing throwing, Stan tries to find the top sticks, that is these sticks such that there is no stick on top of them. Stan has noticed that the last thrown stick is always on top but he wants to know all the sticks that are on top. Stan sticks are very, very thin such that their thickness can be neglected.
Input
Input consists of a number of cases. The data for each case start with 1 ≤ n ≤ 100000, the number of sticks for this case. The following n lines contain four numbers each, these numbers are the planar coordinates of the endpoints of one stick. The sticks are listed in the order in which Stan has thrown them. You may assume that there are no more than 1000 top sticks. The input is ended by the case with n=0. This case should not be processed.
Output
For each input case, print one line of output listing the top sticks in the format given in the sample. The top sticks should be listed in order in which they were thrown.
The picture to the right below illustrates the first case from input.
The picture to the right below illustrates the first case from input.
Sample Input
51 1 4 22 3 3 11 -2.0 8 41 4 8 23 3 6 -2.030 0 1 11 0 2 12 0 3 10
Sample Output
Top sticks: 2, 4, 5.Top sticks: 1, 2, 3.
Source
University of Waterloo Local Contest 2005.09.17
//hdu 1147//#include"stdafx.h"#include<iostream>#include<algorithm>using namespace std;#define size 100010struct point {double x, y;};struct stick{point startpos;point endpos;};stick a[size];bool inter[size];double min(double x, double y) {return x > y ? y : x;}double max(double x, double y) {return x > y ? x : y;}//计算叉积函数double mult(point a, point b, point c) {return (a.x - c.x)*(b.y - c.y) - (b.x - c.x)*(a.y - c.y);}//判断两线段是否相交 相交返回truebool isIntersect(point a,point b,point c,point d) {if (max(a.x, b.x)<min(c.x, d.x))return false;if (max(a.y, b.y)<min(c.y, d.y))return false;if (max(c.x, d.x)<min(a.x, b.x))return false;if (max(c.y, d.y)<min(a.y, b.y))return false;if (mult(c, b, a)*mult(b, d, a)<0)return false;if (mult(a, d, c)*mult(d, b, c)<0)return false;return true;}int main() {int n;while (cin >> n&&n) {memset(a, 0, sizeof(a));memset(inter, false, sizeof(inter));for (int i = 1; i <= n; i++) {cin >> a[i].startpos.x >> a[i].startpos.y >> a[i].endpos.x >> a[i].endpos.y;}for (int i = 1; i <= n - 1; i++) {for (int j = i + 1; j <= n; j++) {if (inter[i])break;//直接break掉 写成continue会超时........//如果相交 则被覆盖 置为trueif (isIntersect(a[i].startpos, a[i].endpos, a[j].startpos, a[j].endpos)) {inter[i] = true;}}}//输出cout << "Top sticks: ";for (int i = 1; i <= n - 1; i++) {if (!inter[i]) {cout << i << ", ";}}cout << n << "." << endl;}return 0;}
阅读全文
1 0
- hdu 1147 pick up sticks 几何问题线段相交
- hdu Pick-up sticks 线段相交问题
- HDU 1147 Pick-up sticks(计算几何 判断直线相交)
- hdu 1147 Pick-up sticks 向量积求线段相交
- HDU 1147 Pick-up sticks(简单的线段相交)
- HDU 1147 Pick-up sticks(线段是否相交)
- hdu 1147 Pick-up sticks(线段相交+枚举)
- hdu acm 1147 Pick-up sticks(判断线段相交)
- hdu-1147 Pick-up sticks(判断线段相交)
- HDU 1147 Pick-up sticks(线段相交)
- poj2653-Pick-up sticks(线段相交问题)
- POJ 2653 Pick-up sticks 计算几何 线段相交
- Pick-up sticks(计算几何_线段相交)
- poj 2653 Pick-up sticks(几何线段相交判断)
- poj2653 Pick-up sticks 计算几何 线段相交
- POJ 2653 Pick-up sticks [线段相交]【计算几何】
- POJ2653---Pick-up sticks (基础计算几何:线段相交问题)
- POJ 2653 Pick-up sticks 线段相交问题
- Hufuman编码
- 大数据环境下的数据安全
- 分布式开源库 介绍
- R语言实战总结 --第二章 数据类型及数据结构
- Linux中vim的文本处理函数
- hdu 1147 pick up sticks 几何问题线段相交
- 【JavaWeb笔记】HTML入门
- 说文解字-JAVA工程师技能分布系列一(JavaSe:面向对象)
- Unity中查找子组件GameObject或Component的操作汇总
- junit单元测试报java.lang.NoSuchMethodError: org.junit.runner.Description.createSuiteDescription
- 总结:大数据几个重要框架的结构框图
- Spring Security 注解备忘
- Android GreenDao 3.0下给数据表的字段设置默认值
- JavaScript 通过Ajax 动态加载CheckBox复选框