zoukankan      html  css  js  c++  java
  • poj2932 Coneology

    地址:http://poj.org/problem?id=2932

    题目:

    Coneology
    Time Limit: 5000MS   Memory Limit: 65536K
    Total Submissions: 4170   Accepted: 886

    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 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

    Source

    思路:

      圆的扫描线算法。

     1 #include <cstdio>
     2 #include <algorithm>
     3 #include <set>
     4 #include <vector>
     5 
     6 #define MP make_pair
     7 #define lc first
     8 #define rc second
     9 
    10 using namespace std;
    11 
    12 const double eps = 1e-8;
    13 const int N = 1e5;
    14 
    15 
    16 int vis[N];
    17 double r[N],cr[N][2];
    18 pair<double,int>pt[N];
    19 set<pair<double,int> >st;
    20 vector<int>ans;
    21 set<pair<double,int> >::iterator it;
    22 int sc(int a,int b)
    23 {
    24     double ta = (cr[a][0]-cr[b][0])*(cr[a][0]-cr[b][0])+(cr[a][1]-cr[b][1])*(cr[a][1]-cr[b][1]);
    25     double tb = (r[a]+r[b])*(r[a]+r[b]);
    26     return ta<tb;
    27 }
    28 int main(void)
    29 {
    30     int n;
    31     while(~scanf("%d",&n))
    32     {
    33         st.clear(),ans.clear();
    34         int cnt=0;
    35         for(int i=1;i<=n;i++)
    36         {
    37             scanf("%lf%lf%lf",r+i,&cr[i][0],&cr[i][1]);
    38             pt[cnt++]=MP(cr[i][0]-r[i],i);
    39             pt[cnt++]=MP(cr[i][0]+r[i],i+n);
    40             vis[i]=0;
    41         }
    42         sort(pt,pt+cnt);
    43         for(int i=0;i<cnt;i++)
    44         {
    45             int k=pt[i].rc;
    46             if(k>n&&vis[k-n])
    47                     st.erase(MP(cr[k-n][1],k-n));
    48             else if(k<=n)
    49             {
    50                 it = st.lower_bound(MP(cr[k][1],0));
    51                 if(it!=st.end()&&sc(k,it->rc))  continue;
    52                 if(it!=st.begin()&&sc(k,(--it)->rc))    continue;
    53                 st.insert(MP(cr[k][1],k));
    54                 vis[k]=1,ans.push_back(k);
    55             }
    56         }
    57         sort(ans.begin(),ans.end());
    58         printf("%d
    ",ans.size());
    59         for(int i=0;i<ans.size();i++)
    60             printf("%d%c",ans[i],i==ans.size()-1?'
    ':' ');
    61         printf("
    ");
    62     }
    63 
    64     return 0;
    65 }
  • 相关阅读:
    ubuntu 12.04 挂载windows分区
    linux ubuntu12.04 配置jdk
    java.lang.IllegalStateException: Cannot forward after response has been committe
    linux ubuntu 安装vim!
    linux ubuntu12.04 eclipse安装 svn
    linux下 android环境配置!
    ubuntu 12.04 配置telnet
    测试下来比较好用的jquery upload插件——uploadify
    google市场又能用了
    当php.ini里post_max_size配置段使用简写法导致php无法接收$_POST值的!
  • 原文地址:https://www.cnblogs.com/weeping/p/7668520.html
Copyright © 2011-2022 走看看