【POJ 1151】 Altlantis
【题目链接】
【算法】
线段树扫描线
推荐一篇比较容易理解的线段树扫描线的文章 : https://blog.csdn.net/u013480600/article/details/22548393
【代码】
注意此题输出格式若使用"%.2lf"会离奇Wrong Answer,要改为"%.2f"
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 110 int i,n,l1,l2,l,L,R,TC;
double xa,ya,xb,yb,area;
double a[MAXN*],x[MAXN*],arr[MAXN*]; struct info {
double l,r,h,opt;
} y[MAXN*]; struct SegmentTree {
struct Node {
int l,r,c;
double m;
} Tree[MAXN*];
inline void build(int index,int l,int r) {
int mid;
Tree[index].l = l;
Tree[index].r = r;
Tree[index].m = 0.0;
Tree[index].c = ;
if (l == r) return;
mid = (l + r) >> ;
build(index<<,l,mid);
build(index<<|,mid+,r);
}
inline void update(int index) {
if (Tree[index].c > ) Tree[index].m = arr[Tree[index].r+] - arr[Tree[index].l];
else if (Tree[index].l == Tree[index].r) Tree[index].m = ;
else Tree[index].m = Tree[index<<].m + Tree[index<<|].m;
}
inline void add(int index,int l,int r,int val) {
int mid;
if (Tree[index].l == l && Tree[index].r == r) {
Tree[index].c += val;
update(index);
return;
}
mid = (Tree[index].l + Tree[index].r) >> ;
if (mid >= r) add(index<<,l,r,val);
else if (mid + <= l) add(index<<|,l,r,val);
else {
add(index<<,l,mid,val);
add(index<<|,mid+,r,val);
}
update(index);
}
inline double query() {
return Tree[].m;
}
} T; bool cmp(info a,info b) { return a.h > b.h; } int main() { while (scanf("%d",&n) != EOF && n) {
l = l1 = l2 = ;
for (i = ; i <= n; i++) {
scanf("%lf%lf%lf%lf",&xa,&ya,&xb,&yb);
x[++l1] = xa;
x[++l1] = xb;
y[++l2] = (info){xa,xb,ya,-};
y[++l2] = (info){xa,xb,yb,};
}
sort(x+,x+l1+);
x[] = -;
for (i = ; i <= l1; i++) {
if (x[i] != x[i-])
arr[++l] = x[i];
}
T.build(,,l-);
sort(y+,y+l2+,cmp);
area = 0.0;
for (i = ; i < l2; i++) {
L = lower_bound(arr+,arr+l+,y[i].l) - arr;
R = lower_bound(arr+,arr+l+,y[i].r) - arr - ;
T.add(,L,R,y[i].opt);
area += T.query() * (y[i].h - y[i+].h);
}
printf("Test case #%d\nTotal explored area: %.2f\n\n",++TC,area);
} return ; }
【POJ 1151】 Altlantis的更多相关文章
- 【POJ 1151】Atlantis
离散化后扫描线扫一遍. 夏令营时gty学长就讲过扫描线,可惜当时too naive,知道现在才写出模板题. 当时也不会线段树啊233 #include<cstdio> #include&l ...
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
- BZOJ2296: 【POJ Challenge】随机种子
2296: [POJ Challenge]随机种子 Time Limit: 1 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 114 Solv ...
- BZOJ2292: 【POJ Challenge 】永远挑战
2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 513 Solved: 201[Submit][ ...
随机推荐
- mysql workbench 导出建表语句
导出建表语句和数据 server—–>data export—–>选中表 注意,export to dump project folder,这种方式是每个表对应一个sql文件. 导出建 ...
- bzoj 5091: [Lydsy0711月赛]摘苹果
5091: [Lydsy0711月赛]摘苹果 Time Limit: 1 Sec Memory Limit: 256 MBSubmit: 148 Solved: 114[Submit][Statu ...
- 问题:typedef char *pstring????
typedef char *pstring; const pstring cstr = 0; //cstr是指向char的常量指针: const pstring *ps; //ps是一个指针,它的对象 ...
- HDD磁盘,非4K无以致远
机械硬盘的未来要靠高容量作为依托,在财报中,希捷表示未来18个月内它们将推出14和16TB机械硬盘,而2020年20TB机械硬盘就将诞生.也有资料显示,3.5英寸100TB硬盘大概在2025年就能面世 ...
- DELPHI方法注释的标准写法
/// <summary> /// 查询数据 /// </summary> /// <param name="accountno">帐套号< ...
- 高仿微信实现左滑显示删除button功能
在实际项目中删除列表中的某一项是很常见的功能.传统的做法能够使用长按监听器等,而如今流行的做法是左滑弹出删除button,微信,QQ等都是这么做的,以下做一个演示样例,代码例如以下: 主页面MainA ...
- angular1.x 组件开发
搜索框组件开发: 1.注册组件 app.js angular.module("myApp",[]) .component("nameSearch",{ temp ...
- POJ训练计划1035_Spell checker(串处理/暴力)
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 18418 Accepted: 6759 De ...
- iOS 小动画
一.图片旋转 CABasicAnimation* rotationAnimation; rotationAnimation = [CABasicAnimation animationWithKeyPa ...
- LeetCode(28)题解:Implement strStr()
https://leetcode.com/problems/implement-strstr/ 题目: Implement strStr(). Returns the index of the fir ...