HDU Atlantis扫描线入门
作者:互联网
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<map>
#include<string>
#include<vector>
#include<set>
#include<bitset>
#include<algorithm>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ull unsigned long long
#define endl '\n'
#define clr(a, b) memset(a, b, sizeof(a))
#define lowbit(x) x & -x
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define PB push_back
#define POP pop_back
const double pi = acos(-1);
const int maxn = 1000 + 10;
const int maxm = (maxn<<5) + 5;
const ll mod = 1e9 + 7;
const int hash_mod = 19260817;
int n, cnt;
double x[maxn];
struct node{
double l, r, h;
int flag;
friend bool operator < (node a, node b){
return a.h < b.h;
}
}line[maxn];
struct nod{
int s;
double len;
}root[maxn];
void pushup(int rt, int l, int r){
if(root[rt].s) root[rt].len = x[r+1] - x[l];
else if(l == r) root[rt].len = 0;
else root[rt].len = root[rt<<1].len + root[rt<<1|1].len;
}
void update(int rt, int l, int r, int L, int R, int f){
if(l == L && R == r){
root[rt].s += f;
pushup(rt, l, r);
return;
}
int mid = (l + r) >> 1;
if(R <= mid) update(lson, L, R, f);
else if(L > mid) update(rson, L, R, f);
else{
update(lson, L, mid, f);
update(rson, mid+1, R, f);
}
pushup(rt, l, r);
}
int main()
{
//freopen("E://one.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取
//freopen("E://oneout.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中
double lx, ly, rx, ry;
int Case = 0;
while(scanf("%d", &n) && n){
double ans = 0.0;
Case ++;
cnt = 0;
clr(root, 0);
for(int i = 1 ; i <= n ; ++ i){
scanf("%lf %lf %lf %lf", &lx, &ly, &rx, &ry);
line[++cnt] = node{lx, rx, ly, 1};
x[cnt] = lx;
line[++cnt] = node{lx, rx, ry, -1};
x[cnt] = rx;
}
sort(line + 1, line + 1 + cnt);
sort(x + 1, x + 1 + cnt);
int len = unique(x + 1, x + 1 + cnt) - x - 1;
for(int i = 1 ; i < cnt ; ++ i){//puts("77");
int l = lower_bound(x + 1, x + 1 + len, line[i].l) - x;
int r = lower_bound(x + 1, x + 1 + len, line[i].r) - x - 1;
//cout << line[i].l << ' ' << line[i].r << endl;
update(1, 1, len - 1, l, r, line[i].flag);
ans += root[1].len * (line[i+1].h - line[i].h);
}
printf("Test case #%d\n", Case);
printf("Total explored area: %.2lf\n\n", ans);
}
return 0;
}
标签:HDU,include,Atlantis,int,mid,long,扫描线,txt,define 来源: https://blog.csdn.net/zufesatoshi/article/details/99692592