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\n",(int)res.size());
38     for(int i = 0; i < res.size(); i ++) {
39         printf("%d%c",res[i]+1, i +1 == res.size() ? '\n':' ');
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 }

 

转载于:https://www.cnblogs.com/xingkongyihao/p/7299592.html

【源码免费下载链接】:https://renmaiwang.cn/s/nhrcw 深度优先搜索(DFS,Depth-First Search)是一种用于遍历或搜索树或图的算法,它选择一个节点并尽可能深地探索其分支。在迷宫生成中,DFS被用来创建复杂的路径结构。以下是对给定内容的详细解释:1. **Python深度优先算法生成迷宫的原理**: 迷宫生成的基本思想是随机地在空白区域添加墙壁,形成一条可以从起点到终点的路径。DFS在这里的作用是从起始点开始,随机选择一个方向进行移动,并将该路径标记为已访问。当遇到障碍(已存在的墙壁)或者到达终点时,算法回溯到上一步,选择其他未尝试过的路径。2. **代码解析**: - 定义矩阵`dfs`来记录迷宫中每个单元格是否已被访问。 - 定义矩阵`maze`来表示最终生成的迷宫,其中`#`代表墙壁,空格代表可通行路径。 - `operation`字典存储了四个可能的方向(上、下、左、右)对应的坐标偏移量。 - `direction`列表包含所有可能的方向,用于随机选择移动方向。 - `stack`用于存储深度优先搜索过程中的路径。3. **函数说明**: - `show(graph)`:打印迷宫矩阵,便于观察迷宫结构。 - `showRouter(stack)`:打印DFS过程中访问的路径,展示从起点到终点的路径。 - `generateMaze(start)`:核心函数,使用DFS生成迷宫。首先将起始点标记为已访问,然后随机排序方向,依次尝试这些方向,如果新位置未被访问且在有效范围内,则打通墙壁并递归调用自身。4. **迷宫生成流程**: - 创建一个全墙的初始迷宫矩阵,奇数行和奇数列的位置代表实际的墙壁,偶数位置代表路径。 - 起点设为`(0, 0)`,调用`generateMaze((0,0))`开始生成迷宫。 - 在递归过程中,每次
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值