• poj2653


    暴力题

    注意vector用法,erase函数返回的是删除后的下一个元素的指针。迭代器的写法是:vector<  >::iterator i;

    View Code
    #include <iostream>
    #include
    <cstdlib>
    #include
    <cstring>
    #include
    <cstdio>
    #include
    <vector>
    using namespace std;

    #define maxn 100005
    #define eps 1e-10

    struct Point
    {
    double x, y;
    };

    struct Line
    {
    Point a, b;
    } line[maxn];

    vector
    <int> stk(maxn);
    int n;

    void input()
    {
    for (int i = 0; i < n; i++)
    scanf(
    "%lf%lf%lf%lf", &line[i].a.x, &line[i].a.y, &line[i].b.x, &line[i].b.y);
    }

    bool 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 0;
    double h = (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
    double i = (b.x - a.x) * (d.y - a.y) - (b.y - a.y) * (d.x - a.x);
    double j = (d.x - c.x) * (a.y - c.y) - (d.y - c.y) * (a.x - c.x);
    double k = (d.x - c.x) * (b.y - c.y) - (d.y - c.y) * (b.x - c.x);
    return h * i <= eps && j * k <= eps;
    }

    bool cross(Line &p, Line &q)
    {
    return inter(p.a, p.b, q.a, q.b);
    }

    void make(Line &l)
    {
    for (vector<int>::iterator i = stk.begin(); i < stk.end();)
    {
    if (cross(line[*i], l))
    i
    = stk.erase(i);
    else
    i
    ++;
    }
    }

    void work()
    {
    for (int i = 0; i < n; i++)
    {
    make(line[i]);
    stk.push_back(i);
    }
    printf(
    "Top sticks: %d", stk[0] + 1);
    for (vector<int>::iterator i = stk.begin() + 1; i < stk.end(); i++)
    printf(
    ", %d", (*i) + 1);
    printf(
    ".\n");
    }

    int main()
    {
    //freopen("t.txt", "r", stdin);
    while (scanf("%d", &n), n)
    {
    stk.clear();
    input();
    work();
    }
    return 0;
    }
  • 相关阅读:
    linux中inittab文件详解
    Linux的 test 命令使用
    程序的链接和装入及Linux下动态链接的实现
    linux虚拟内存管理简要总结
    一些vim技巧和经验
    Linux cp mv rm ln 命令对于 inode 和 dentry 的影响
    Linux C编程一站式学习
    虚拟内存管理
    为何cp覆盖进程的动态库(so)会导致coredump
    linux下So覆盖导致coredump问题的分析
  • 原文地址:https://www.cnblogs.com/rainydays/p/2172211.html
Copyright © 2020-2023  润新知