uva 688 - Mobile Phone Coverage

经典问题,矩形面积并。

解法:一、矩形分割,每个矩形的两个横坐标和两个纵坐标排序,这样得到2n*2n个区间,对这些区间依次判断是否包含在n个矩形中间即可。

      二、扫描线。具体还没实现过。

详见:http://www.algorithmist.com/index.php/UVa_688

另:http://www.ii.uni.wroc.pl/boi/index.phtml?id=11

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 using namespace std;
 5
 6 int main()
 7 {
 8     int n, i, j, k, cases;
 9     double area, x[105], y[105], r[105], dx[105*2], dy[105*2];
10     cases = 0;
11     while(cin>>n && n)
12     {
13         for(i=0; i<n; i++)
14         {
15             cin >> x[i] >> y[i] >> r[i];
16             dx[i*2] = x[i] - r[i], dx[i*2+1] = x[i] + r[i];
17             dy[i*2] = y[i] - r[i], dy[i*2+1] = y[i] + r[i];
18         }
19         sort(dx, dx+2*n);
20         sort(dy, dy+2*n);
21         area = 0.0;
22         for(i = 1; i < 2*n; i++)
23             for(j = 1; j < 2*n; j++)
24                 for(k = 0; k < n; k++)
25                 {
26                     if(dx[i-1]>=x[k]-r[k] && dx[i]<=x[k]+r[k])
27                         if(dy[j-1]>=y[k]-r[k] && dy[j]<=y[k]+r[k])
28                         {
29                             area += (dx[i] - dx[i-1]) * (dy[j] - dy[j-1]);
30                             break;
31                         }
32                 }
33         printf("%d %.2lf\n", ++cases, area);
34     }
35     return 0;
36 }
时间: 2024-08-10 02:09:20

uva 688 - Mobile Phone Coverage的相关文章

UVa 1354 Mobile Computing[暴力枚举]

**1354 Mobile Computing** There is a mysterious planet called Yaen, whose space is 2-dimensional. There are many beautiful stones on the planet, and the Yaen people love to collect them. They bring the stones back home and make nice mobile arts of th

UVa 1354 Mobile Computing | GOJ 1320 不加修饰的天平问题

传送门1(UVa): https://uva.onlinejudge.org/external/13/1354.pdf 传送门2(GOJ): http://acm.gdufe.edu.cn/Problem/read/id/1320 题意: 长度限制 r (1 < r < 10), 给 n (1 <= n <= 6) 个砝码,组成平衡(考虑重量和力臂)的天平,求天平最长能多长. 2015个人选拔赛#6 1004 比赛的时候完全不知道怎么做,比赛完两天重新看一遍有点思路就是敲不出来(弱

uva 1354 Mobile Computing ——yhx

1 #include<cstdio> 2 #include<cmath> 3 #include<cstring> 4 struct node 5 { 6 int fat,lson,rson; 7 double wei; 8 }tree[500]; 9 double w[10],lim,ans; 10 int n; 11 double max(double x,double y) 12 { 13 return x>y?x:y; 14 } 15 void calc_s

zoj 1659 Mobile Phone Coverage(矩形面积并)

题意:每组数据给出正方形中点坐标及半边长,求矩形面积并: 思路:采用沿垂直方向计算矩形面积并的方法,把面积切成若干垂直条再累加.zoj上能过,但Uva688却一直RE,已经尝试过开大空间了... #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; const double epsi=1e-10; const int maxn=4

Uva 1354 Mobile Computing

题目链接 题意: 在一个宽为r 的房间里, 有s个砝码, 每个天平的一端要么挂砝码, 要么挂另一个天平, 并且每个天平要保持平衡. 求使得所有砝码都放在天平上, 且总宽度不超过房间宽度的最大值. 思路: 每个节点只能有两个子节点, 这是一棵二叉树的形式. 通过枚举二叉树的形态, 再枚举每一个叶子节点所放砝码, 最后再计算每个方案的宽度并计算答案. 每增加一个天平, 那么可以放砝码数 + 1. note: 坑在0的输出了, 用primtf("%.9lf\n", 0)输出来的是0  用0.

UVA 1354 Mobile Computing(天平难题,枚举子集,递归,好题*)

1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 5 /** 6 思路:在每一个根节点枚举左右子树 7 8 学习: 9 (1)枚举子集的方法 例如 枚举 s = 100101 的子集 10 for(int l = (s-1)&s , l > 0 ; l = (l-1) & s){ 11 int r = s ^ l; 12 (2)思考:如何表示 左边距离 右边距离 . 该点的

UVA 12166-Equilibrium Mobile(推导结论)

题目大意:给出一棵二叉树,整个树是天平,每个结点有一个砝码或一个天平,对于任意一个天平,绳子都在中点,每个砝码都有重量,求最少修改多少个砝码的重量使得整个天平平衡. 本题的关键在于一个结论:若最终天平平衡,则在同一个深度的所有结点,无论它的祖先结点是什么,重量都应该相同.并且上一层的重量应该是下一层的2倍.证明其实是显然的.. 之后只需要把所有的结点分块,然后取结点最多的块,其余的结点都要修改,就是答案. 分块的规则是按照结论顺其自然得出的:假设节点u在第i层,v在第j层并且i<=j,那么u和v

UVA Planning mobile robot on Tree树上的机器人(状态压缩+bfs)

用(x,s)表示一个状态,x表示机器人的位置,s表示其他位置有没有物体.用个fa数组和act数组记录和打印路径,转移的时候判断一下是不是机器人在动. #include<bits/stdc++.h> using namespace std; const int maxn = 16; const int maxe = 32; const int MAXSTA = 491520+10; // 2^15*15 int head[maxn],to[maxe],nxt[maxe]; int ecnt; v

ZOJ1659_Mobile Phone Coverage(扫描线/线段树+离散)

解题报告 题目传送门 题意: 求矩形面积并 思路: 扫描线+线段树.要离散化,坐标是浮点型的. 对于线段树(区间)与点坐标对应起来可以这样 区间[1,4]对应的线段树. #include <algorithm> #include <iostream> #include <cstring> #include <cstdio> using namespace std; struct Seg { int v; double lx,rx,h; friend bool