【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][ ...
随机推荐
- AC日记——A+B Problem(再升级) 洛谷 P1832
题目背景 ·题目名称是吸引你点进来的 ·实际上该题还是很水的 题目描述 ·1+1=? 显然是2 ·a+b=? 1001回看不谢 ·哥德巴赫猜想 似乎已呈泛滥趋势 ·以上纯属个人吐槽 ·给定一个正整数n ...
- CODEVS_1227 方格取数2 网络流 最小费用流 拆点
原题链接:http://codevs.cn/problem/1227/ 题目描述 Description 给出一个n*n的矩阵,每一格有一个非负整数Aij,(Aij <= 1000)现在从(1, ...
- luogu P1476 休息中的小呆
题目描述 当大家在考场中接受考验(折磨?)的时候,小呆正在悠闲(欠扁)地玩一个叫“最初梦想”的游戏.游戏描述的是一个叫pass的有志少年在不同的时空穿越对抗传说中的大魔王chinesesonic的故事 ...
- 洛谷 P1503鬼子进村
题目背景 小卡正在新家的客厅中看电视.电视里正在播放放了千八百次依旧重播的<亮剑>,剧中李云龙带领的独立团在一个县城遇到了一个鬼子小队,于是独立团与鬼子展开游击战. 题目描述 描述 县城里 ...
- 实验十二 swing图形界面设计
1.源程序 package information;import java.awt.Container;import java.awt.FlowLayout;import java.awt.event ...
- MySql 初始化权限脚本
刚装好MySql后无法用客户端工具连接,通过命令行登录后,运行下面的脚本: GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'y ...
- 【hibernate spring data jpa】执行了save()方法 sql语句也执行了,但是数据并未插入数据库中
执行了save()方法 sql语句也执行了,但是数据并未插入数据库中 解决方法: 是因为执行了save()方法,也执行了sql语句,但是因为使用的是 @Transactional 注解,不是手动去提 ...
- oracle下session的查询与删除
oracle下session的查询与删除 1.查询当前session SQL> select username,sid,serial# from v$session where username ...
- Our happy ending
题目链接 题意: 输入n.k.L,n个数,最大值不超过L,在序列中取若干个数和能达到k的序列个数 n,k<=20 , 0<=L<=10^9 分析: 题目关键在于和k比較小,所以能够考 ...
- spring MVC使用Interceptor做用户登录判断
在任何一个项目中,我们必须要用到的就是用户登录,那么就少不了用户是否登录的判断,如果我们每一个请求都要去做一次判断,那么就会变得很麻烦,但我们复制粘贴的时候我们就要考虑我们的代码写的是不是有问题,是不 ...