HDU 1542 Atlantis(矩形面积并)
来源:互联网 发布:大数据风控模型 编辑:程序博客网 时间:2024/05/17 23:06
HDU 1542 Atlantis
题目链接
题意:给定一些矩形,求面积并
思路:利用扫描线,由于这题矩形个数不多,直接暴力扫就可以了,如果数据大,就要用线段树
代码:
#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;const int N = 205;const int M = 100005;const double eps = 1e-8;int n, vis[N], hn;double hash[N];struct Line {double l, r, y;int flag;Line() {}Line(double l, double r, double y, int flag) {this->l = l;this->r = r;this->y = y;this->flag = flag;}} line[N];bool cmp(Line a, Line b) {return a.y < b.y;}int get(double x) {return lower_bound(hash, hash + hn, x) - hash;}int main() {int cas = 0;while (~scanf("%d", &n) && n) {double x1, x2, y1, y2; hn = 0;memset(vis, 0, sizeof(vis));for (int i = 0; i < n; i++) {scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);line[i * 2] = Line(x1, x2, y1, 1);line[i * 2 + 1] = Line(x1, x2, y2, -1);hash[hn++] = x1; hash[hn++] = x2;}n *= 2;sort(line, line + n, cmp);sort(hash, hash + hn);hn = 1;for (int i = 1; i < n; i++) {if (fabs(hash[i] - hash[i - 1]) < eps) continue;hash[hn++] = hash[i];}double ans = 0;for (int i = 0; i < n; i++) {int l = get(line[i].l), r = get(line[i].r);double len = 0;for (int j = 0; j < hn - 1; j++) if (vis[j] > 0) len += (hash[j + 1] - hash[j]);if (i) ans += len * (line[i].y - line[i - 1].y);for (int j = l; j < r; j++) vis[j] += line[i].flag;}printf("Test case #%d\n", ++cas);printf("Total explored area: %.2lf\n\n", ans);}return 0;}
0 0
- hdu 1542 Atlantis(矩形面积并)
- HDU 1542 Atlantis(矩形面积并)
- HDU 1542 Atlantis (矩形面积并)
- HDU 1542 Atlantis 矩形面积并
- 矩形面积并 hdu 1542 Atlantis
- hdu 1542 Atlantis(矩形面积并)
- hdu 1542 Atlantis 矩形面积并
- hdu 1542 Atlantis(矩形面积并)
- HDU 1542 Atlantis(线段树求矩形面积并)
- HDU 1542 Atlantis(线段树求矩形面积并)
- HDU 1542 Atlantis(矩形并的面积)
- hdu 1542(线段树 求矩形面积并)Atlantis
- Hdu 1542 Atlantis 线段树 求矩形面积并
- Hdu 1542/ POj 1151 Atlantis 线段树+矩形面积并
- HDU-1542 Atlantis 矩形面积并 扫描线
- hdu 1542 Atlantis 线段树矩形面积并+离散化
- HDU 1542 —— Atlantis 【矩形面积并:扫描线】
- hdu 1542 Atlantis (线段树求矩形面积并)
- cocos2d-x总结
- 关于支付宝合作者身份id与与卖家支付宝账号
- Cocos2d-x V3.2+Cocos Studio1.6 实现一个简单的uibutton点击功能
- Unity3D学习笔记 碰撞检测
- oracle死锁的解决方法
- HDU 1542 Atlantis(矩形面积并)
- java冒泡排序(从小到大、从大到小)
- 论证是一门学问 如何让你的观点有说服力-8 规则8 使用有代表性的例子
- 标准C预处理器(指令)
- 炼数成金-数据分析展现与R语言15周完整版
- Netty 基本使用,比Mina要稳定的多。
- cocos2d-x基础1
- 黑洞数问题
- Unity NGUI 使用经验