poj2932 Coneology
地址:http://poj.org/problem?id=2932
题目:
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 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
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\n",ans.size()); 59 for(int i=0;i<ans.size();i++) 60 printf("%d%c",ans[i],i==ans.size()-1?'\n':' '); 61 printf("\n"); 62 } 63 64 return 0; 65 }
作者:weeping
出处:www.cnblogs.com/weeping/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 智能桌面机器人:用.NET IoT库控制舵机并多方法播放表情
· Linux glibc自带哈希表的用例及性能测试
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
· DeepSeek火爆全网,官网宕机?本地部署一个随便玩「LLM探索」
· 开发者新选择:用DeepSeek实现Cursor级智能编程的免费方案
· 【译】.NET 升级助手现在支持升级到集中式包管理
· 独立开发经验谈:如何通过 Docker 让潜在客户快速体验你的系统
· Tinyfox 发生重大改版