POJ 2653 Pick-up sticks(线段相交)
题意:给定n个木棍依次放下,要求最终判断没被覆盖的木棍是哪些。
思路:快速排斥以及跨立实验可以判断线段相交。
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
const double eps=1e-;
struct Point{
double x,y;
Point(){}
Point(double x0,double y0):x(x0),y(y0){}
}s[],e[];
int ans[],st[],n;
double operator *(Point p1,Point p2){
return p1.x*p2.y-p1.y*p2.x;
}
Point operator -(Point p1,Point p2){
return Point(p1.x-p2.x,p1.y-p2.y);
}
bool judge(Point p1,Point p2,Point p3,Point p4){
if (std::min(p1.x,p2.x)>std::max(p3.x,p4.x)||
std::min(p1.y,p2.y)>std::max(p3.y,p4.y)||
std::min(p3.x,p4.x)>std::max(p1.x,p2.x)||
std::min(p3.y,p4.y)>std::max(p1.y,p2.y))
return ;//快速排斥实验
double a,b,c,d;
a=(p2-p1)*(p3-p1);
b=(p2-p1)*(p4-p1);
c=(p4-p3)*(p1-p3);
d=(p4-p3)*(p2-p3);
return (a*b<=eps)&&(c*d<=eps);//跨立实验
}
int main(){
while (scanf("%d",&n)!=EOF&&n){
for (int i=;i<=n;i++) ans[i]=;
for (int i=;i<=n;i++){
scanf("%lf%lf%lf%lf",&s[i].x,&s[i].y,&e[i].x,&e[i].y);
}
for (int i=;i<=n;i++)
for (int j=i+;j<=n;j++)
if (judge(s[i],e[i],s[j],e[j]))
{ ans[i]=;
break;
}
int top=;
for (int i=;i<=n;i++)
if (!ans[i])
st[++top]=i;
printf("Top sticks:");
for (int i=;i<top;i++)
printf(" %d,",st[i]);
printf(" %d.\n",st[top]);
}
}
POJ 2653 Pick-up sticks(线段相交)的更多相关文章
- 【POJ 2653】Pick-up sticks 判断线段相交
一定要注意位运算的优先级!!!我被这个卡了好久 判断线段相交模板题. 叉积,点积,规范相交,非规范相交的简单模板 用了“链表”优化之后还是$O(n^2)$的暴力,可是为什么能过$10^5$的数据? # ...
- POJ 2653 Pick-up sticks [线段相交 迷之暴力]
Pick-up sticks Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 12861 Accepted: 4847 D ...
- POJ 1066 Treasure Hunt (线段相交)
题意:给你一个100*100的正方形,再给你n条线(墙),保证线段一定在正方形内且端点在正方形边界(外墙),最后给你一个正方形内的点(保证不再墙上) 告诉你墙之间(包括外墙)围成了一些小房间,在小房间 ...
- POJ 1410 Intersection --几何,线段相交
题意: 给一条线段,和一个矩形,问线段是否与矩形相交或在矩形内. 解法: 判断是否在矩形内,如果不在,判断与四条边是否相交即可.这题让我发现自己的线段相交函数有错误的地方,原来我写的线段相交函数就是单 ...
- POJ 1269 Intersecting Lines(线段相交,水题)
id=1269" rel="nofollow">Intersecting Lines 大意:给你两条直线的坐标,推断两条直线是否共线.平行.相交.若相交.求出交点. ...
- POJ 1066 Treasure Hunt【线段相交】
思路:枚举四边墙的门的中点,与终点连成一条线段,判断与其相交的线段的个数.最小的加一即为答案. 我是傻逼,一个数组越界调了两个小时. #include<stdio.h> #include& ...
- poj 1556 (Dijkstra + Geometry 线段相交)
链接:http://poj.org/problem?id=1556 The Doors Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- POJ 3304 Segments[直线与线段相交]
Segments Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13514 Accepted: 4331 Descrip ...
- POJ 1408 Fishnet【枚举+线段相交+叉积求面积】
题目: http://poj.org/problem?id=1408 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
随机推荐
- Verdigris: Qt without moc
https://woboq.com/blog/verdigris-qt-without-moc.html https://github.com/woboq/verdigris
- jQuery手机触屏左右滑动切换焦点图特效代码
原文地址:http://www.17sucai.com/pins/4857.html 演示地址:http://www.17sucai.com/pins/demoshow/4857 干净演示地址:htt ...
- POJ2367 Genealogical tree (拓扑排序)
裸拓扑排序. 拓扑排序 用一个队列实现,先把入度为0的点放入队列.然后考虑不断在图中删除队列中的点,每次删除一个点会产生一些新的入度为0的点.把这些点插入队列. 注意:有向无环图 g[] : g[i] ...
- poj 3273 Monthly Expense(二分搜索之最大化最小值)
Description Farmer John ≤ moneyi ≤ ,) that he will need to spend each day over the next N ( ≤ N ≤ ,) ...
- mavne install 报错org.apache.maven.surefire.util.SurefireReflectionException: java.lang.reflect.InvocationTargetException
maven install 报错 org.apache.maven.surefire.util.SurefireReflectionException: java.lang.reflect.Invoc ...
- 1042. Shuffling Machine (20) - sstream实现数字转字符串
题目例如以下: Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffli ...
- UIApplication的作用
1.设置app图标右上角的数字2.设置状态栏的属性(样式.是否要显示)3.打开某个链接\发短信\打电话4.keyWindow : 访问程序的主窗口(一个程序只能有一个主窗口)5.windows : 访 ...
- Angular单页应用&AngularJS内部实现原理
回顾 自定义指令 登录后获取登录信息session 首先在登录验证的时候保存一个user 在学生管理页面中运用ajax调用获取到登录的用户信息 对注销按钮添加点击事件:调用ajax在表现层给user赋 ...
- DBHerperl类
using System; using System.Collections.Generic; using System.Text; using System.Data; using System.D ...
- 微软HoloLens虚拟现实可以开发了。
1.microsoft-hololens-now-available-to-developers 2.http://www.microsoft.com/microsoft-hololens/en-us ...