题目传送门

题意:就是小时候玩的一种游戏,问有多少线段盖在最上面

分析:简单线段相交,队列维护当前最上的线段

/************************************************
* Author        :Running_Time
* Created Time  :2015/10/26 星期一 15:37:36
* File Name     :POJ_2653.cpp************************************************/#include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std;#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos (-1.0);
int dcmp(double x)  {       //三态函数,减少精度问题if (fabs (x) < EPS) return 0;else    return x < 0 ? -1 : 1;
}
struct Point    {       //点的定义double x, y;Point (double x=0, double y=0) : x (x), y (y) {}Point operator + (const Point &r) const {       //向量加法return Point (x + r.x, y + r.y);}Point operator - (const Point &r) const {       //向量减法return Point (x - r.x, y - r.y);}Point operator * (double p)  {       //向量乘以标量return Point (x * p, y * p);}Point operator / (double p)  {       //向量除以标量return Point (x / p, y / p);}bool operator < (const Point &r) const {       //点的坐标排序return x < r.x || (x == r.x && y < r.y);}bool operator == (const Point &r) const {       //判断同一个点return dcmp (x - r.x) == 0 && dcmp (y - r.y) == 0;}
};
typedef Point Vector;       //向量的定义
Point read_point(void)   {      //点的读入double x, y;scanf ("%lf%lf", &x, &y);return Point (x, y);
}
double dot(Vector A, Vector B)  {       //向量点积return A.x * B.x + A.y * B.y;
}
double cross(Vector A, Vector B)    {       //向量叉积return A.x * B.y - A.y * B.x;
}
double polar_angle(Vector A)  {     //向量极角return atan2 (A.y, A.x);
}
double length(Vector A) {       //向量长度,点积return sqrt (dot (A, A));
}
double angle(Vector A, Vector B)    {       //向量转角,逆时针,点积return acos (dot (A, B) / length (A) / length (B));
}
Vector rotate(Vector A, double rad) {       //向量旋转,逆时针return Vector (A.x * cos (rad) - A.y * sin (rad), A.x * sin (rad) + A.y * cos (rad));
}
Vector nomal(Vector A)  {       //向量的单位法向量double len = length (A);return Vector (-A.y / len, A.x / len);
}
Point line_line_inter(Point p, Vector V, Point q, Vector W)    {        //两直线交点,参数方程Vector U = p - q;double t = cross (W, U) / cross (V, W);return p + V * t;
}
double point_to_line(Point p, Point a, Point b)   {       //点到直线的距离,两点式Vector V1 = b - a, V2 = p - a;return fabs (cross (V1, V2)) / length (V1);
}
double point_to_seg(Point p, Point a, Point b)    {       //点到线段的距离,两点式if (a == b) return length (p - a);Vector V1 = b - a, V2 = p - a, V3 = p - b;if (dcmp (dot (V1, V2)) < 0)    return length (V2);else if (dcmp (dot (V1, V3)) > 0)   return length (V3);else    return fabs (cross (V1, V2)) / length (V1);
}
Point point_line_proj(Point p, Point a, Point b)   {     //点在直线上的投影,两点式Vector V = b - a;return a + V * (dot (V, p - a) / dot (V, V));
}
bool can_inter(Point a1, Point a2, Point b1, Point b2)  {       //判断线段相交,两点式double c1 = cross (a2 - a1, b1 - a1), c2 = cross (a2 - a1, b2 - a1),c3 = cross (b2 - b1, a1 - b1), c4 = cross (b2 - b1, a2 - b1);return dcmp (c1) * dcmp (c2) < 0 && dcmp (c3) * dcmp (c4) < 0;
}
bool on_seg(Point p, Point a1, Point a2)    {       //判断点在线段上,两点式return dcmp (cross (a1 - p, a2 - p)) == 0 && dcmp (dot (a1 - p, a2 - p)) < 0;
}
double area_triangle(Point a, Point b, Point c) {       //三角形面积,叉积return fabs (cross (b - a, c - a)) / 2.0;
}
double area_poly(Point *p, int n)   {       //多边形面积,叉积double ret = 0;for (int i=1; i<n-1; ++i)   {ret += fabs (cross (p[i] - p[0], p[i+1] - p[0]));}return ret / 2;
}
/*点集凸包
*/
vector<Point> convex_hull(vector<Point> &P) {sort (P.begin (), P.end ());int n = P.size (), k = 0;vector<Point> ret (n * 2);for (int i=0; i<n; ++i) {while (k > 1 && cross (ret[k-1] - ret[k-2], P[i] - ret[k-1]) <= 0)  k--;ret[k++] = P[i];}for (int i=n-2, t=k; i>=0; --i)  {while (k > t && cross (ret[k-1] - ret[k-2], P[i] - ret[k-1]) <= 0)  k--;ret[k++] = P[i];}ret.resize (k-1);return ret;
}struct Circle   {Point c;double r;Circle () {}Circle (Point c, double r) : c (c), r (r) {}Point point(double a)   {return Point (c.x + cos (a) * r, c.y + sin (a) * r);}
};
struct Line {Point p;Vector v;double r;Line () {}Line (const Point &p, const Vector &v) : p (p), v (v) {r = polar_angle (v);}Point point(double a)   {return p + v * a;}
};Point s[N], e[N];
bool vis[N];int main(void)    {int n;while (scanf ("%d", &n) == 1)   {if (!n) break;memset (vis, true, sizeof (vis));for (int i=1; i<=n; ++i)    {s[i] = read_point ();e[i] = read_point ();}queue<int> Q;   Q.push (1);for (int i=2; i<=n; ++i)    {Q.push (i);while (!Q.empty ()) {if (i == Q.front ())    break;int j = Q.front (); Q.pop ();if (can_inter (s[i], e[i], s[j], e[j])) {vis[j] = false;}else    Q.push (j);}}printf ("Top sticks: ");bool fir = true;for (int i=1; i<=n; ++i)    {if (vis[i]) {if (fir)    {printf ("%d", i);   fir = false;}else    {printf (", %d", i);}}}puts (".");}//cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";return 0;
}

  

转载于:https://www.cnblogs.com/Running-Time/p/4911773.html

简单几何(线段相交) POJ 2653 Pick-up sticks相关推荐

  1. 简单几何(线段相交+最短路) POJ 1556 The Doors

    题目传送门 题意:从(0, 5)走到(10, 5),中间有一些门,走的路是直线,问最短的距离 分析:关键是建图,可以保存所有的点,两点连通的条件是线段和中间的线段都不相交,建立有向图,然后用Dijks ...

  2. 简单几何(线段覆盖) POJ 3347 Kadj Squares

    题目传送门 题意:告诉每个矩形的边长,它们是紧贴着的,问从上往下看,有几个还能看到. 分析:用网上猥琐的方法,将边长看成左端点到中心的距离,这样可以避免精度问题.然后先求出每个矩形的左右端点,然后如果 ...

  3. 简单几何(极角排序) POJ 2007 Scrambled Polygon

    题目传送门 题意:裸的对原点的极角排序,凸包貌似不行. /************************************************ * Author :Running_Time ...

  4. 【代码超详解】ZOJ 2551 / POJ 2653 Pick-up Sticks(快速排斥实验 + 跨立实验判断线段是否相交 · 模板)

    一.传送门 http://poj.org/problem?id=2653 https://zoj.pintia.cn/problem-sets/91827364500/problems/9182736 ...

  5. POJ 2653 Pick-up sticks (线段相交)

    题意:给你n条线段依次放到二维平面上,问最后有哪些没与前面的线段相交,即它是顶上的线段 题解:数据弱,正向纯模拟可过 但是有一个陷阱:如果我们从后面向前枚举,找与前面哪些相交,再删除前面那些相交的线段 ...

  6. POJ 2653 线段交

    思路: 运用队列存储没有被覆盖的木棍,没加入一个棍子,就要判断一下是否队列中的棍子被覆盖,如果被覆盖,就从队列中删除: 线段交判断方法:跨立实验 Pick-up sticks Time Limit: ...

  7. 判断线段和直线相交 POJ 3304

    1 // 判断线段和直线相交 POJ 3304 2 // 思路: 3 // 如果存在一条直线和所有线段相交,那么平移该直线一定可以经过线段上任意两个点,并且和所有线段相交. 4 5 #include ...

  8. 几何常用算法与判断线段相交【转】

    下面这个函数在我写的计算几何库函数里面有,那个库可以在http://algorithm.126.com/的资源中心   -   代码角   找到. 算法简单说明: 首先判断以两条线段为对角线的矩形是否 ...

  9. POJ - 3304 Segments(简单几何)

    题目链接:点击查看 题目大意:给出n条线段,现在问是否存在一条直线,使得所有线段向这条直线的投影存在一个共同的交点 题目分析:题意有点抽象,需要转换一下,因为所有的线段向某一条直线的投影存在一个交点, ...

  10. 【POJ - 1556】The Doors (计算几何,线段相交)

    题干: You are to find the length of the shortest path through a chamber containing obstructing walls. ...

最新文章

  1. u-boot中filesize环境变量【转载】
  2. 为什么说python是世界上最好的语言-Python才是世界上最好的语言
  3. C语言经典例32-删除字符串中指定的字符
  4. esp8266 阿里云 arduino_ESP8266接入阿里云——基于官方SDK接入阿里云串口获取云下发数据...
  5. 【POJ - 1486】Sorting Slides(思维建图,二分图求必须边,关建边,图论)
  6. 图像基础知识 —— Opencv图像处理
  7. mvc ajax返回整个页面跳转,在springmvc中的ajax发布调用之后,有什么方法可以将我的页面(jsp)重定向到另一个页面(jsp)...
  8. 特征码的使用办法_小脚的美丽与哀愁,34/35码的她们都是怎么买鞋的?
  9. VMplayer创建虚拟机
  10. 一些简单的css,html,js笔记分享给大家,希望能够帮助到大家
  11. c# datetime._C#| DateTime.TimeOfDay属性(带示例)
  12. 服务器 z盘 映射,小脚本:在终端上映射网络驱动器Z盘
  13. 基于51,人体红外感应和RC522的门禁系统
  14. 国内外6款优秀的免费CDN服务
  15. uefi启动解析:由原理到实例
  16. ChatGPT怎么突然变得这么强?华人博士万字长文深度拆解GPT-3.5能力起源
  17. qq发送编程相关的命令或代码时,被转成表情该怎么解决
  18. HTML字体以及图标字体iconfont、Font Awesome的使用
  19. 公路养护管理:高速公路养护施工安全管理探析
  20. 以雪为命题,写一篇500字文章。

热门文章

  1. 手把手教您安全配置Apache服务器
  2. 一位70后的感叹:下半辈子我会陷入贫困吗?
  3. 为什么阿里规定需要在事务注解 @Transactional 中指定 rollbackFor?这...
  4. 再见!LayUI !
  5. Kafka 居然还会丢消息?
  6. 进入大厂的面试经验详细总结(P7 拿 offer)
  7. 牛逼了,竟然真的有程序员做出了一套完整的地府后台管理系统,还开源了
  8. Docker 架构原理剖析,万字详解!
  9. 阿里专家:怎么样消除程序员的中年危机?
  10. 最全 MySQL 优化方法,从此优化不再难