POJ 1151 HDU 1542 Atlantis(扫描线)

本文介绍了一种使用扫描线算法解决地图区域叠加问题的方法。通过离散化x坐标并利用线段树进行区间更新,实现了对多个矩形区域重叠部分的总面积计算。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目大意就是:去一个地方探险,然后给你一些地图描写叙述这个地方,每一个描写叙述是一个矩形的右下角和左上角。地图有些地方是重叠的。所以让你求出被描写叙述的地方的总面积。

扫描线的第一道题,想了又想,啸爷还给我讲了讲,最终有点理解了啊。

先说扫描线:书上说扫描线不是一个物体。而是一个概念。

在计算几何中的作用类似于图论中的bfs与dfs。所以还是须要多做题目来体会一下啊。

这道题目的做法是:离散化x坐标。然后依照y坐标的大小进行排序,每一条保存它的左边界的位置与右边界的位置。以及自身的高度。

还有就是假设是下边初始为1。上边初始为-1。

接下来就是扫描线了:依照y值排序后的数组,開始遍历。

先二分查找它在离散数组中下表的位置。找到之后按他保存的边界的标记。进行更新。这里的区间更新用的是线段树的维护。我们以离散化后数组建树。

每一个节点保存它此时有多少个上界与下界的和,表示他是否存在矩形。

假设存在的话每一个节点中用sun数组保存这个矩形x值的差值(通过这个离散区间的下标,做减法就是离散的x的差值)。最后的时候乘上y的差值。

就是扫描到的矩阵的面积。

Atlantis
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 17207 Accepted: 6549

Description

There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some of these texts even include maps of parts of the island. But unfortunately, these maps describe different regions of Atlantis. Your friend Bill has to know the total area for which maps exist. You (unwisely) volunteered to write a program that calculates this quantity.

Input

The input consists of several test cases. Each test case starts with a line containing a single integer n (1 <= n <= 100) of available maps. The n following lines describe one map each. Each of these lines contains four numbers x1;y1;x2;y2 (0 <= x1 < x2 <= 100000;0 <= y1 < y2 <= 100000), not necessarily integers. The values (x1; y1) and (x2;y2) are the coordinates of the top-left resp. bottom-right corner of the mapped area. 
The input file is terminated by a line containing a single 0. Don't process it.

Output

For each test case, your program should output one section. The first line of each section must be "Test case #k", where k is the number of the test case (starting with 1). The second one must be "Total explored area: a", where a is the total explored area (i.e. the area of the union of all rectangles in this test case), printed exact to two digits to the right of the decimal point. 
Output a blank line after each test case.

Sample Input

2
10 10 20 20
15 15 25 25.5
0

Sample Output

Test case #1
Total explored area: 180.00 

Source

#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <ctime>
#include <map>
#include <set>
#define eps 1e-12
///#define M 1000100
#define LL __int64
///#define LL long long
///#define INF 0x7ffffff
#define INF 0x3f3f3f3f
#define PI 3.1415926535898
#define zero(x) ((fabs(x)<eps)?0:x)

using namespace std;

const int maxn = 5010;

struct node
{
    double l, r, h;
    int x;
} f[maxn];

double sum[maxn<<2];
int cnt[maxn];
double dc[maxn];

bool cmp(node a, node b)
{
    return a.h < b.h;
}

int Find(double x, double a[], int n)
{
    int l = 0;
    int r = n-1;
    while(l <= r)
    {
        int mid = (l+r)/2;
        if(a[mid] == x) return mid;
        if(a[mid] > x) r = mid-1;
        else l = mid+1;
    }
    return -1;

}

void Up(int l, int r, int site)
{
    if(cnt[site]) sum[site] = dc[r+1]-dc[l];
    else if(l == r) sum[site] = 0;
    else sum[site] = sum[site<<1]+sum[site<<1|1];
}

void Update(int l, int r, int L, int R, int d, int site)
{
    if(L <= l && r <= R)
    {
        cnt[site] += d;
        Up(l, r, site);
        return;
    }
    int mid = (l+r)>>1;
    if(L <= mid) Update(l, mid, L, R, d, site<<1);
    if(R > mid) Update(mid+1, r, L, R, d, site<<1|1);
    Up(l, r, site);
}

int main()
{
    int n;
    int Case = 1;
    while(cin >>n)
    {
        if(!n) break;
        double x1, y1, x2, y2;
        int m = 0;
        for(int i = 0; i < n; i++)
        {
            scanf("%lf %lf %lf %lf",&x1, &y1, &x2, &y2);
            dc[m] = x1;
            f[m].l = x1;
            f[m].r = x2;
            f[m].h = y1;
            f[m++].x = 1;
            dc[m] = x2;
            f[m].l = x1;
            f[m].r = x2;
            f[m].h = y2;
            f[m++].x = -1;
        }
        sort(dc, dc+m);
        sort(f, f+m, cmp);
        int k = unique(dc, dc+m)-dc;
        memset(cnt, 0 , sizeof(cnt));
        memset(sum, 0 , sizeof(sum));
        double ans = 0;
        for(int i = 0; i < m-1; i++)
        {
            int l = Find(f[i].l, dc, k);
            int r = Find(f[i].r, dc, k)-1;
            if(l <= r) Update(0, k-1, l, r, f[i].x, 1);
            ans += sum[1]*(f[i+1].h-f[i].h);
        }
        printf("Test case #%d\n",Case++);
        printf("Total explored area: %.2f\n\n",ans);
    }
    return 0;
}


内容概要:本文针对国内加密货币市场预测研究较少的现状,采用BP神经网络构建了CCi30指数预测模型。研究选取2018年3月1日至2019年3月26日共391天的数据作为样本,通过“试凑法”确定最优隐结点数目,建立三层BP神经网络模型对CCi30指数收盘价进行预测。论文详细介绍了数据预处理、模型构建、训练及评估过程,包括数据归一化、特征工程、模型架构设计(如输入层、隐藏层、输出层)、模型编译与训练、模型评估(如RMSE、MAE计算)以及结果可视化。研究表明,该模型在短期内能较准确地预测指数变化趋势。此外,文章还讨论了隐层节点数的优化方法及其对预测性能的影响,并提出了若干改进建议,如引入更多技术指标、优化模型架构、尝试其他时序模型等。 适合人群:对加密货币市场预测感兴趣的研究人员、投资者及具备一定编程基础的数据分析师。 使用场景及目标:①为加密货币市场投资者提供一种新的预测工具和方法;②帮助研究人员理解BP神经网络在时间序列预测中的应用;③为后续研究提供改进方向,如数据增强、模型优化、特征工程等。 其他说明:尽管该模型在短期内表现出良好的预测性能,但仍存在一定局限性,如样本量较小、未考虑外部因素影响等。因此,在实际应用中需谨慎对待模型预测结果,并结合其他分析工具共同决策。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值