poj 1151 Atlantis

poj 1151
Atlantis
Time Limit: 1000MS   Memory Limit: 10000KB   64bit IO Format: %I64d & %I64u

[Submit]   [Go Back]   [Status]

Description

There are several ancient Greek texts that contain descri_ptions 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 

[Submit]   [Go Back]   [Status]


/*

from:http://www.cppblog.com/RyanWang/archive/2009/02/22/74612.html

这道题是离散化的入门题。

问题描述:一些已知右下顶点和左上顶点坐标的矩形,这些矩形可能部分重叠,求它们所占的实际面积。

离散化

1、首先分离出所有的横坐标和纵坐标分别按升序存入数组X[ ]和Y[ ]中.

2、 设数组XY[ ][ ].对于每个矩形(x1,y1)(x2,y2)确定i1,i2,j1,j2,使得,X[i1]>x1,X[i2]<=x2,Y[i1]>y1,Y[i2]>=y2令XY[ i ][ j ] = 1 (i从i1到i2,j从j1到j2)

3、统计面积:area+=XY[i][j] *(X[i]-X[i-1])*(Y[i] – Y[i-1])


我一开始没弄明白。。。。。真是一个好的方法。。太巧妙了!

*/


#include<iostream>

using namespace std;

double x[201],y[201],s[101][4];

int xy[201][201];

int n,cas=0;

double sum;

int main()

{

    int i,j,k;

    while(cin>>n)

    {

        if(n==0)

            break;

        cas++;

        k=0;

        sum=0.0;

        memset(xy,0,sizeof(xy));

        for(i=1;i<=n;i++)

        {

            cin>>s[i][0]>>s[i][1]>>s[i][2]>>s[i][3];

            x[k]=s[i][0];

            y[k]=s[i][1];

            k++;

            x[k]=s[i][2];

            y[k]=s[i][3];

            k++;

        }

        sort(x,x+2*n);

        sort(y,y+2*n);

        for(k=1;k<=n;k++)

        {

            int i1,i2,j1,j2;

            for(i1=0;i1<2*n;i1++)

            {

                if(x[i1]==s[k][0])

                    break;

            }

            for(i2=0;i2<2*n;i2++)

            {

                if(x[i2]==s[k][2])

                    break;

            }

            for(j1=0;j1<2*n;j1++)

            {

                if(y[j1]==s[k][1])

                    break;

            }

            for(j2=0;j2<2*n;j2++)

            {

                if(y[j2]==s[k][3])

                    break;

            }

            for(i=i1;i<i2;i++)

            {

                for(j=j1;j<j2;j++)

                {

                    xy[i][j]=1;

                }

            }

        }

        for(i=0;i<2*n;i++)

        {

            for(j=0;j<2*n;j++)

            {

                sum+=xy[i][j]*(x[i+1]-x[i])*(y[j+1]-y[j]);

            }

        }

        printf("Test case #%d\n",cas);

        printf("Total explored area: %.2f\n",sum);

        printf("\n");

    }

    system("pause");

    return 0;

}

内容概要:本研究聚焦于绿电直连型电氢氨园区的优化运行,提出一种集成绿色电力直接供给、电解水制氢及氢气合成氨工艺的综合能源系统架构。通过建立包含风光发电、电解槽、氨合成反应器、储氢罐、电网交互及多类型负荷在内的系统模型,综合考虑绿电直供优先、能量梯级利用与多能互补原则,构建以系统综合运行成本最小化为目标的优化调度模型。研究采用Matlab与Python工具进行算法求解和仿真分析,利用实际气象与负荷数据完成案例验证,评估了不同运行策略下系统的经济性、可再生能源消纳能力与碳减排效益,为新型电氢氨一体化园区的规划与运行提供了理论依据和技术支撑。; 适合人群:具备一定电力系统、新能源或化工背景的研究生、科研人员及从事综合能源系统规划与优化工作的工程技术人员。; 使用场景及目标:①用于科研学习,理解电-氢-氨多能转换系统的建模与优化方法;②为工业园区的低碳化、智能化改造提供技术参考与决策支持;③作为开发类似综合能源管理系统的理论基础。; 阅读建议:此资源包含完整的模型代码、数据与论文,使用者应结合代码仔细研读论文中的模型构建部分,重点关注目标函数与约束条件的设计逻辑,并尝试修改参数进行仿真,以深入掌握优化算法在实际系统中的应用。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值