【HDOJ】1542 Atlantis
离散化+线段树+扫描线,求覆盖面积。
/* 1542 */
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000") #define sti set<int>
#define stpii set<pair<int, int> >
#define mpii map<int,int>
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define clr clear
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 typedef struct segment_t {
double l, r, h;
int f; friend bool operator< (const segment_t& a, const segment_t& b) {
return a.h < b.h;
} } segment_t; typedef struct {
int l, r, c;
double len;
} node_t; const int maxn = ;
double X[maxn];
segment_t seg[maxn];
node_t nd[maxn<<]; void build(int l, int r, int rt) {
nd[rt].l = l;
nd[rt].r = r;
nd[rt].c = ;
nd[rt].len = ; if (l == r)
return ; int mid = (l + r) >> ;
build(lson);
build(rson);
} void PushUp(int rt) {
if (nd[rt].c)
nd[rt].len = X[nd[rt].r+] - X[nd[rt].l];
else if (nd[rt].r == nd[rt].l)
nd[rt].len = ;
else
nd[rt].len = nd[rt<<].len + nd[rt<<|].len;
} void update(int L, int R, int delta, int rt) {
if (L<=nd[rt].l && nd[rt].r<=R) {
nd[rt].c += delta;
PushUp(rt);
return ;
} int mid = (nd[rt].l + nd[rt].r) >> ; if (mid >= R) {
update(L, R, delta, rt<<);
} else if (mid < L) {
update(L, R, delta, rt<<|);
} else {
update(L, R, delta, rt<<);
update(L, R, delta, rt<<|);
} PushUp(rt);
} int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif int n, m, xn;
double x1, x2, y1, y2;
double ans;
int L, R;
int tt = ; while (scanf("%d",&n)!=EOF && n) {
ans = .;
m = ;
rep(i, , n) {
scanf("%lf %lf %lf %lf", &x1,&y1,&x2,&y2);
seg[m].l = seg[m+].l = x1;
seg[m].r = seg[m+].r = x2;
seg[m].h = y1;
seg[m].f = ;
seg[m+].h = y2;
seg[m+].f = -; X[m] = x1;
X[m+] = x2; m += ;
} sort(seg, seg+m);
sort(X, X+m);
xn = unique(X, X+m)-X; build(, xn-, ); rep(i, , m) {
L = lower_bound(X, X+xn, seg[i].l) - X;
R = lower_bound(X, X+xn, seg[i].r) - X - ;
update(L, R, seg[i].f, );
ans += (seg[i+].h - seg[i].h) * nd[].len;
#ifndef ONLINE_JUDGE
printf("L = %d, R = %d, len = %.2lf\n", L, R, nd[].len);
#endif
} printf("Test case #%d\n", ++tt);
printf("Total explored area: %.02lf\n\n", ans);
} #ifndef ONLINE_JUDGE
printf("time = %d.\n", (int)clock());
#endif return ;
}
【HDOJ】1542 Atlantis的更多相关文章
- 【HDOJ】4729 An Easy Problem for Elfness
其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...
- 【POJ】1151 Atlantis(线段树)
http://poj.org/problem?id=1151 经典矩形面积并吧.....很简单我就不说了... 有个很神的地方,我脑残没想到: 将线段变成点啊QAQ这样方便计算了啊 还有个很坑的地方, ...
- 【HDOJ】【3506】Monkey Party
DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...
- 【HDOJ】【3516】Tree Construction
DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...
- 【HDOJ】【3480】Division
DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...
- 【HDOJ】【2829】Lawrence
DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...
- 【HDOJ】【3415】Max Sum of Max-K-sub-sequence
DP/单调队列优化 呃……环形链求最大k子段和. 首先拆环为链求前缀和…… 然后单调队列吧<_<,裸题没啥好说的…… WA:为毛手写队列就会挂,必须用STL的deque?(写挂自己弱……s ...
- 【HDOJ】【3530】Subsequence
DP/单调队列优化 题解:http://www.cnblogs.com/yymore/archive/2011/06/22/2087553.html 引用: 首先我们要明确几件事情 1.假设我们现在知 ...
- 【HDOJ】【3068】最长回文
Manacher算法 Manacher模板题…… //HDOJ 3068 #include<cstdio> #include<cstring> #include<cstd ...
随机推荐
- C# 调试程序弹出 没有可用于当前位置的源代码 对话框
解决方案: 1.右键点击解决方案->属性->通用属性->调试源文件. 2.看看你的程序有没有被增加到“不查找这些源文件”这个框里. 3.如果有删除,然后重新编译即可调试,解决问题.
- C# Generic(转载)
型(generic)是C#语言2.0和通用语言运行时(CLR)的一个新特性.泛型为.NET框架引入了类型参数(type parameters)的概念.类型参数使得设计类和方法时,不必确定一个或多个具体 ...
- IO流04_InputStream和Reader输入流
[输入流中的字符流和字节流] [InputStream和Reader] InputStream和Reader是所有输入流的抽象基类,本身不能实例化,但是他们是所有输入流的模板. [ InputStre ...
- FileInputStream 与 BufferedInputStream 效率对比
我的技术博客经常被流氓网站恶意爬取转载.请移步原文:http://www.cnblogs.com/hamhog/p/3550158.html ,享受整齐的排版.有效的链接.正确的代码缩进.更好的阅读体 ...
- 安装kali之后
更新源(以下设置均基于这些源) #vi /etc/apt/sources.list 把这些源加进去 ############################ debian wheezy ####### ...
- msyql判断记录是否存在的三种方法
1. select count(*) from .... 这种方法最常见但是效率比较低,因为它需要扫描所有满足条件的记录 2. select 1 from xxxtable where .... 这种 ...
- YII2框架动态创建表模型
YII2框架动态创建表模型 在YII2中,每个表对应一个model类 在开发过程中,我们在填写一个大型表单的时候,表单里有N个select下拉列表,每个下拉select来自于不同的表: 如果要在程序里 ...
- python zookeeper 学习笔记
1.安装zookeeper 下载zookeeper后,解压,安装 cd zookeeper-/src/c ./configure make make install 2.启动zookeeper服务 c ...
- hdu 3234 Exclusive-OR
Exclusive-OR 题意:输入n个点和Q次操作(1 <= n <= 20,000, 2 <= Q <= 40,000).操作和叙述的点标号k(0 < k < ...
- java学习--抽象类与接口
一.抽象 在使用抽象类时需要注意几点: 1.抽象类不能被实例化,实例化的工作应该交由它的子类来完成,它只需要有一个引用即可. 2.抽象方法必须由子类来进行重写. 3.只要包含一个抽象方法的抽象类,该方 ...