zoukankan      html  css  js  c++  java
  • POJ2932 平面扫描

    Description

    A student named Round Square loved to play with cones. He would arrange cones with different base radii arbitrarily on the floor and would admire the intrinsic beauty of the arrangement. The student even began theorizing about how some cones dominate other cones: a cone A dominates another cone B when cone B is completely within the cone A. Furthermore, he noted that there are some cones that not only dominate others, but are themselves dominated, thus creating complex domination relations. After studying the intricate relations of the cones in more depth, the student reached an important conclusion: there exist some cones, all-powerful cones, that have unique properties: an all-powerful cone is not dominated by any other cone. The student became so impressed by the mightiness of the all-powerful cones that he decided to worship these all-powerful cones.

    Unfortunately, after having arranged a huge number of cones and having worked hard on developing this grandiose cone theory, the student become quite confused with all these cones, and he now fears that he might worship the wrong cones (what if there is an evil cone that tries to trick the student into worshiping it?). You need to help this student by finding the cones he should worship.

    Input

    The input le specifies an arrangement of the cones. There are in total N cones (1 ≤ N ≤ 40000). Cone i has radius and height equal to Ri, i = 1 … N. Each cone is hollow on the inside and has no base, so it can be placed over another cone with smaller radius. No two cones touch.

    The first line of the input contains the integer N. The next N lines each contain three real numbers Ri, xi, yi separated by spaces, where (xi, yi) are the coordinates of the center of the base of cone i.

    Output

    The first line of the output le should contain the number of cones that the student should worship. The second line contains the indices of the cones that the student should worship in increasing order. Two consecutive numbers should be separated by a single space.

    Sample Input

    5
    1 0 -2
    3 0 3
    10 0 0
    1 0 1.5
    10 50 50

    Sample Output

    2
    3 5
    平面有N个两两没有公共点的园,i号园的园心在(xi, yi),半径ri。求所有最外层,即不包含其他园内部的园。
    我们可以在从左向右平移与y轴平行的直线的同时,维护与扫描线相交的最外层的园的集合。从左向右移动的过程中,只有扫描线移动到园的左右两端时,园与扫描线的相交关系才会发生变化,
    因此我们先将所有这样的x坐标枚举出来并排号序。扫描到左端时,只要判断是否被包含在相邻的园中就行,因为假设该园被包含在更远的园中却不包含在最近的园中就会出现两园相交的情况,与题目两两没有公共点的园相矛盾。

     1 #include <iostream>
     2 #include <string.h>
     3 #include <algorithm>
     4 #include <stdio.h>
     5 #include <vector>
     6 #include <set>
     7 using namespace std;
     8 const int N = 40010;
     9 double x[N], y[N], r[N];
    10 int n;
    11 bool inside(int i, int j) {
    12     double dx = x[i] - x[j], dy = y[i] - y[j];
    13     return dx * dx + dy * dy <= r[j] * r[j];
    14 }
    15 void solve() {
    16     vector<pair<double, int> > events;
    17     for(int i = 0; i < n; i ++) {
    18         events.push_back(make_pair(x[i] - r[i], i));
    19         events.push_back(make_pair(x[i] + r[i], i+n));
    20     }
    21     sort(events.begin(), events.end());
    22     set<pair<double, int> > st;
    23     vector<int> res;
    24     for(int i = 0; i < events.size(); i ++) {
    25         int id = events[i].second % n;
    26         if(events[i].second < n) {
    27             set<pair<double, int> > ::iterator it = st.lower_bound(make_pair(y[id], id));
    28             if(it != st.end() && inside(id, it->second)) continue;
    29             if(it != st.begin() && inside(id, (--it)->second)) continue;
    30             res.push_back(id);
    31             st.insert(make_pair(y[id], id));
    32         } else {
    33             st.erase(make_pair(y[id], id));
    34         }
    35     }
    36     sort(res.begin(), res.end());
    37     printf("%d
    ",(int)res.size());
    38     for(int i = 0; i < res.size(); i ++) {
    39         printf("%d%c",res[i]+1, i +1 == res.size() ? '
    ':' ');
    40     }
    41 }
    42 int main() {
    43     scanf("%d", &n);
    44     for(int i = 0; i < n; i ++) {
    45         scanf("%lf %lf %lf", &r[i], &x[i], &y[i]);
    46     }
    47     solve();
    48     return 0;
    49 }
  • 相关阅读:
    PSNR计算
    Latex中的(左边有大括号的)方程组解决方案汇总
    CS (Compressive sensing, 压缩传感)
    OpenCV 2.3.0 编译错误之 file INSTALL cannot find opencv_ffmpeg230d.dll(无法找到opencv_ffmpeg230d.dll)
    Visual Studio 2008 编译程序时的 mt.exe 返回错误
    fontDialog,colorDialog,saveDialog改变字体大小,颜色,以后保存图片文件实例
    Lambda入门示例实例
    C#接口入门基础知识复习
    C#,visual studio 2010中实现最简单DragDrop实例
    抽象类实现条件参数必须和抽象类中的一样
  • 原文地址:https://www.cnblogs.com/xingkongyihao/p/7299592.html
Copyright © 2011-2022 走看看