题意:给定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(线段相交)的更多相关文章

  1. 【POJ 2653】Pick-up sticks 判断线段相交

    一定要注意位运算的优先级!!!我被这个卡了好久 判断线段相交模板题. 叉积,点积,规范相交,非规范相交的简单模板 用了“链表”优化之后还是$O(n^2)$的暴力,可是为什么能过$10^5$的数据? # ...

  2. POJ 2653 Pick-up sticks [线段相交 迷之暴力]

    Pick-up sticks Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 12861   Accepted: 4847 D ...

  3. POJ 1066 Treasure Hunt (线段相交)

    题意:给你一个100*100的正方形,再给你n条线(墙),保证线段一定在正方形内且端点在正方形边界(外墙),最后给你一个正方形内的点(保证不再墙上) 告诉你墙之间(包括外墙)围成了一些小房间,在小房间 ...

  4. POJ 1410 Intersection --几何,线段相交

    题意: 给一条线段,和一个矩形,问线段是否与矩形相交或在矩形内. 解法: 判断是否在矩形内,如果不在,判断与四条边是否相交即可.这题让我发现自己的线段相交函数有错误的地方,原来我写的线段相交函数就是单 ...

  5. POJ 1269 Intersecting Lines(线段相交,水题)

    id=1269" rel="nofollow">Intersecting Lines 大意:给你两条直线的坐标,推断两条直线是否共线.平行.相交.若相交.求出交点. ...

  6. POJ 1066 Treasure Hunt【线段相交】

    思路:枚举四边墙的门的中点,与终点连成一条线段,判断与其相交的线段的个数.最小的加一即为答案. 我是傻逼,一个数组越界调了两个小时. #include<stdio.h> #include& ...

  7. poj 1556 (Dijkstra + Geometry 线段相交)

    链接:http://poj.org/problem?id=1556 The Doors Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

  8. POJ 3304 Segments[直线与线段相交]

    Segments Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13514   Accepted: 4331 Descrip ...

  9. POJ 1408 Fishnet【枚举+线段相交+叉积求面积】

    题目: http://poj.org/problem?id=1408 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

随机推荐

  1. 安装AD15有问题多数是因为旧版本AD软件没有卸载干净,清理方法详解

    论坛中总会看到有些朋友安装AD14.x,AD15.x后,使用不正常,多数情况是因为旧版本的AD软件没有卸载干净,安装新版本AD软件后,就会有问题.卸载和清理AD旧版本软件的方法如下(此方法只能解决卸载 ...

  2. 关于Python的3张图

  3. Cmake Error: your compiler "cl" was not Found .etc

    又是环境变量路径等问题,烦死人了. TIPS:请注意,控制台的窗口也有自己的环境变量,从系统环境变量和用户环境变量继承过来的,一个窗口(控制台)可以添加属于自己的环境变量(跟别的控制台窗口没关系) 解 ...

  4. 黑马程序员_Java基本数据类型对象包装类

    基本数据类型对象包装类 byte Byte short Short int Integer long Long boolean Boolean float Float double Double ch ...

  5. hdu 2817 A sequence of numbers(快速幂)

    Problem Description Xinlv wrote some sequences on the paper a long time ago, they might be arithmeti ...

  6. (转)Building MariaDB on Mac OS X using Homebrew

    https://kb.askmonty.org/en/building-mariadb-on-mac-os-x-using-homebrew/ Work has been done to provid ...

  7. 讲解版的自动轮播(新手福利)样式和js就不分离了为了看的方便

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  8. 支持多QQ登录的软件

    支持多QQ登录,批量加好友,批量回复QQ消息,当然也能接收 下载链接:多QQ登录软件

  9. 批量SSH操作工具---OmniTTY安装

    安装rote # pwd /tmp/rote-0.2.8 # ./configure # make # make install ...... mkdir -p /usr/local/include/ ...

  10. python - 消息队列

    消息队列分类 1.先进先出 2.后进先出 3.优先级队列 4.双向队列 1.先进先出 import queue q = queue.Queue(2) #队列最大长度 q.put(11) q.put(2 ...