zoukankan      html  css  js  c++  java
  • poj2932 Coneology (扫描线)

    转载请注明出处: http://www.cnblogs.com/fraud/           ——by fraud

    Coneology
    Time Limit: 5000MS   Memory Limit: 65536K
    Total Submissions: 3289   Accepted: 586

    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 dominateother 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 Rii = 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 Rixiyi separated by spaces, where (xiyi) 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

    这题并不难,和多校的某道题稍微思想上有点像。

    问不包含于其他圆内部的圆的数目。

    取所有的左端点和右端点,排序后一次取,对于在内部的圆,其外部的圆一定只取到了左端点,那么我们对于当前只取到左端点的圆,只需要判断这个圆的纵坐标是否在那些只取到左端点的圆的纵坐标之间。因为不会相交,所以可以这样搞。

     1 /**
     2  * code generated by JHelper
     3  * More info: https://github.com/AlexeyDmitriev/JHelper
     4  * @author xyiyy @https://github.com/xyiyy
     5  */
     6 
     7 #include <iostream>
     8 #include <fstream>
     9 
    10 //#####################
    11 //Author:fraud
    12 //Blog: http://www.cnblogs.com/fraud/
    13 //#####################
    14 //#pragma comment(linker, "/STACK:102400000,102400000")
    15 #include <iostream>
    16 #include <sstream>
    17 #include <ios>
    18 #include <iomanip>
    19 #include <functional>
    20 #include <algorithm>
    21 #include <vector>
    22 #include <string>
    23 #include <list>
    24 #include <queue>
    25 #include <deque>
    26 #include <stack>
    27 #include <set>
    28 #include <map>
    29 #include <cstdio>
    30 #include <cstdlib>
    31 #include <cmath>
    32 #include <cstring>
    33 #include <climits>
    34 #include <cctype>
    35 
    36 using namespace std;
    37 #define mp(X, Y) make_pair(X,Y)
    38 #define pb(X) push_back(X)
    39 #define rep(X, N) for(int X=0;X<N;X++)
    40 #define IT iterator
    41 #define ALL(X) (X).begin(),(X).end()
    42 
    43 double r[40010], x[40010], y[40010];
    44 vector<pair<double, int> > vec;
    45 set<pair<double, int> > s;
    46 bool mark[40010];
    47 vector<int> ans;
    48 
    49 bool contain(int a, int b) {
    50     return ((x[a] - x[b]) * (x[a] - x[b]) + (y[a] - y[b]) * (y[a] - y[b]) <= r[b] * r[b]);
    51 }
    52 
    53 class poj2932 {
    54 public:
    55     void solve(std::istream &in, std::ostream &out) {
    56         int n;
    57         while (in >> n) {
    58             vec.clear();
    59             s.clear();
    60             ans.clear();
    61             rep(i, n)in >> r[i] >> x[i] >> y[i];
    62             rep(i, n) {
    63                 vec.pb(mp(x[i] - r[i], i));
    64                 vec.pb(mp(x[i] + r[i], i + n));
    65             }
    66             sort(ALL(vec));
    67             int num = 0;
    68             rep(i, vec.size()) {
    69                 int j = vec[i].second;
    70                 if (j < n) {
    71                     set<pair<double, int> >::IT it = s.lower_bound(mp(y[j], j));
    72                     if (it != s.end() && contain(j, it->second))continue;
    73                     if (it != s.begin() && contain(j, (--it)->second))continue;
    74                     s.insert(mp(y[j], j));
    75                     mark[j + 1] = 1;
    76                     num++;
    77                 } else {
    78                     s.erase(mp(y[j - n], j - n));
    79                 }
    80             }
    81             out << num << endl;
    82             rep(i, n) {
    83                 if (mark[i + 1])out << i + 1 << " ";
    84             }
    85             out << endl;
    86         }
    87     }
    88 };
    89 
    90 int main() {
    91     std::ios::sync_with_stdio(false);
    92     std::cin.tie(0);
    93     poj2932 solver;
    94     std::istream &in(std::cin);
    95     std::ostream &out(std::cout);
    96     solver.solve(in, out);
    97     return 0;
    98 }
    代码君
  • 相关阅读:
    Codeforces 401C Team 贪心法
    C++ 编译,执行过程 具体解释。
    [从头学数学] 第156节 概率初步
    关于flex,好像有12个属性非常重要
    数据清洗小记(12):姓与名的提取
    理解Angular中的$apply()以及$digest()
    Oracle开发者守则
    黑马程序猿——25,打印流,合并流,对象序列化,管道流,RandomAccessFile
    GPU 编程入门到精通(四)之 GPU 程序优化
    Python 面向对象编程 继承 和多态
  • 原文地址:https://www.cnblogs.com/fraud/p/4771990.html
Copyright © 2011-2022 走看看