这个题 就是个工程题 (然而一开始我并不知道怎么做。。还是看nocow的。。qwq)(原题入口

算法为 离散化 + 扫描线  将大坐标变小  并且 用横纵坐标进行扫描 来计算面积

一开始 我想边添加 点的坐标 边 离散  后来发现 有点问题

因为 它离散后的坐标 并不是按顺序来排(因为后来可能还加入中间的点 就需要重新离散)

所以 我就把一开始的操作 和 坐标先存下来 进行离散 再进行操作 (QAQ 搞了好久)

后面 就是计算面积了 把一个大矩形 划分成 许多个小矩形 再进行标记 来计算面积了

代码:

 #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cctype>
#include <iostream>
#include <map>
#include <vector>
#define For(i, l, r) for(int i = (l); i <= (int)(r); ++i)
#define Fordown(i, r, l) for(int i = (r); i >= (int)(l); --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define pb push_back
using namespace std; inline int read(){
int x = , fh = ; char ch;
for(; !isdigit(ch); ch = getchar()) if (ch == '-') fh = -;
for(; isdigit(ch); ch = getchar()) x = (x<<) + (x<<) + (ch^'');
return x * fh;
} const int N = ;
map <int, int> fx, fy; //map数组 记录这个坐标是否被离散化过
int gx[<<], gy[<<]; //反向存储标号对应的坐标
int cnt_x = , cnt_y = , cnt = ; //离散化的个数
char id[N]; //记录id数组 int now_deep = *(<<), top_deep = (<<), back_deep = *(<<);
struct node {
int xl, yl, xr, yr;
int deep; //层次
bool flag; //是否被删除
};
node win[N]; //存储窗户 int idx(char ch) {
For (i, , cnt)
if (id[i] == ch) return i;
id[++cnt] = ch;
return cnt;
} //计算当前l的id bool exist[N/][N/];
double sum(int num) {
if (!win[num].flag) return 0.0000; //如果已经删除 就返回0.0 (好像并没有用)
Set(exist, false); //判断小矩形是否存在
int sum_area = ;
int now_area = ; For (i, win[num].xl, win[num].xr-)
For (j, win[num].yl, win[num].yr-)
{ exist[i][j] = true; //一开始置为真
sum_area += fabs ((gx[i+] - gx[i] ) * (gy[j+] - gy[j]) ) ; } //计算本来的总面积 For (i, , cnt)
if (win[i].flag && win[i].deep < win[num].deep) //如果在它上面 并且 未被删除
For (j, win[i].xl, win[i].xr-)
For (k, win[i].yl, win[i].yr-)
exist[j][k] = false; //小矩形置为假 For (i, win[num].xl, win[num].xr-)
For (j, win[num].yl, win[num].yr-)
if (exist[i][j]) //存在 就加上
now_area += fabs( (gx[i] - gx[i+]) * (gy[j] - gy[j+]) ); //计算面积 return ((double)now_area / (double)sum_area * 100.0000); //计算百分比
} struct oper {
char opt;
int l, xl, yl, xr, yr;
}; oper kk[N]; //存储操作
int cnt_op = ;
vector <int> tx; //存储坐标
vector <int> ty; int main(){
freopen ("window.in", "r", stdin);
freopen ("window.out", "w", stdout);
char opt;
while (scanf ("%c", &opt) != EOF) {
char l;
int xl1, yl1, xr1, yr1;
if (opt == 'w') {
scanf ("(%c,%d,%d,%d,%d)", &l, &xl1, &yl1, &xr1, &yr1);
if (xl1 > xr1) swap(xl1, xr1);
if (yl1 > yr1) swap(yl1, yr1); //左下角 和 右上角
kk[++cnt_op] = (oper) {opt, l, xl1, yl1, xr1, yr1};
tx.pb (xl1); tx.pb(xr1); ty.pb(yl1); ty.pb(yr1);
}
else {
scanf ("(%c)", &l);
kk[++cnt_op] = (oper) {opt, l, , , , };
}
} sort (tx.begin(), tx.end() );
For (i, , tx.size() - )
if (!fx[tx[i]] ) {fx[tx[i]] = ++cnt_x; gx[cnt_x] = tx[i]; }
sort (ty.begin(), ty.end() );
For (i, , ty.size() - )
if (!fy[ty[i]] ) {fy[ty[i]] = ++cnt_y; gy[cnt_y] = ty[i]; }
//运用map的离散化 可能有点慢 For (i, , cnt_op) {
//cout << "id: " << i << endl;
opt = kk[i].opt;
char l = kk[i].l; int num;
int xl1 = kk[i].xl, yl1 = kk[i].yl, xr1 = kk[i].xr, yr1 = kk[i].yr;
if (opt == 'w') {
num = idx(l);
win[num].xl = fx[xl1]; win[num].xr = fx[xr1];
win[num].yl = fy[yl1]; win[num].yr = fy[yr1];
win[num].flag = true; win[num].deep = --top_deep; //放在最上面 并将flag为真
} //创建一个新窗体(window)
else if (opt == 't') {
num = idx(l);
win[num].deep = --top_deep;
}//将窗体置顶(top)
else if (opt == 'b') {
num = idx(l);
win[num].deep = ++back_deep;
}//将窗体置底(back)
else if (opt == 'd') {
num = idx(l);
win[num].flag = false;
// cout << num << endl;
}//删除一个窗体(delete)
else if (opt == 's') {
num = idx(l);
printf ("%.3lf\n", sum(num));
}//输出窗体可见部分的百分比(sum)
}
}

luogu【P2745】[USACO5.3]窗体面积Window Area的更多相关文章

  1. [洛谷P2745] [USACO5.3]窗体面积Window Area

    洛谷题目链接:[USACO5.3]窗体面积Window Area 题目描述 你刚刚接手一项窗体界面工程.窗体界面还算简单,而且幸运的是,你不必显示实际的窗体.有 5 种基本操作: 创建一个新窗体 将窗 ...

  2. 无废话ExtJs 入门教程三[窗体:Window组件]

    无废话ExtJs 入门教程三[窗体:Window组件] extjs技术交流,欢迎加群(201926085) 1.代码如下: 1 <!DOCTYPE html PUBLIC "-//W3 ...

  3. USACO 5.3 Window Area

    Window AreaIV Balkan Olympiad You've just be assigned the project of implemented a windowing interfa ...

  4. [Luogu P1345] [USACO5.4]奶牛的电信Telecowmunication (最小割)

    题面 传送门:https://www.luogu.org/problemnew/show/P1345 ] Solution 这道题,需要一个小技巧了解决. 我相信很多像我这样接蒟蒻,看到这道题,不禁兴 ...

  5. 洛谷U2641 木板面积(area)——S.B.S.

    题目背景 一年一次的夏令营又要开始了,卡卡西和小伙伴们早就做好了准备,满心期 待着这趟快乐之旅.在一个阳光明媚的清晨,卡卡西在老师的带领下来到了这次 夏令营的首站——“神奇木材加工厂” . 题目描述 ...

  6. [Swift]LeetCode223. 矩形面积 | Rectangle Area

    Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined b ...

  7. [Swift]LeetCode695. 岛屿的最大面积 | Max Area of Island

    Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) conn ...

  8. LeetCode 223. 矩形面积(Rectangle Area)

    223. 矩形面积 223. Rectangle Area 题目描述 在二维平面上计算出两个由直线构成的矩形重叠后形成的总面积. 每个矩形由其左下顶点和右上顶点坐标表示,如图所示. LeetCode2 ...

  9. 面积(area)

    题目描述 编程计算由"*"号围成的下列图形的面积.面积计算方法是统计*号所围成的闭合曲线中点的数目.如图所示,在10*10的二维数组中,“*”围住了15个点,因此面积为15. 0 ...

随机推荐

  1. Windows Server 2012开启多人远程

    首先在Server Roles中选择Remote Desktop Services,然后在Role Services中安装Remote Desktop Session Host 安装完成后需要重启机器 ...

  2. SQL Server 文件操作

    在master数据库中,SQL Server提供系统扩展的存储过程,其中有一些存储过程的命名以xp_开头,用于处理操作系统的文件. 一,判断文件是否存在 存储过程sys.xp_fileexist 用于 ...

  3. 利用ajax获取网页表单数据,并存储到数据库之一(使用JDBC)

    所谓JDBC就是利用java与数据库相连接的技术,从数据库获取既有的信息或者把网页上的信息存储到数据库. 这里简单的介绍公司的一个小项目中的一部分,由于代码较多,所以用图片形式进行展示.源码请查看源码 ...

  4. hibernate的事务管理和session对象的详解

    //开启事务 transaction=session.beginTransaction(); 上面为开启事务 transaction.commit();这个为提交事务 从session对象中获取事务后 ...

  5. Git (gnome-ssh-askpass:3871): Gtk-WARNING **: cannot open display:

    在使用Git在客户端使用git push 命令提交文件到github时,出现报错 (gnome-ssh-askpass:): Gtk-WARNING **: cannot open display: ...

  6. 在linux ubuntu下搭建深度学习/机器学习开发环境

    一.安装Anaconda 1.下载 下载地址为:https://www.anaconda.com/download/#linux 2.安装anaconda,执行命令: bash ~/Downloads ...

  7. 《android开发艺术探索》读书笔记(八)--WindowManager

    接上篇<android开发艺术探索>读书笔记(七)--动画 No1: Window是一个抽象类,它的具体实现是PhoneWindow.创建一个Window是很简单的事,只需要通过Windo ...

  8. hihoCoder 1051 : 补提交卡 枚举

    思路:预处理cnt(i)表示前i个数中有多少天需要补提交卡,枚举各个连续区间,区间[j, i]中需要补提交卡的天数是cnt(i) - cnt(j-1),判断m是否大于等于cnt(i) - cnt(j- ...

  9. js基本类型与引用类型,浅拷贝和深拷贝

    1. 基本类型: string,number,boolean,null,undefined 2. 引用类型: Function,Array,Object 基本类型:存放在栈内存中的简单数据段,数据大小 ...

  10. 移动端-手机端-日历选择控件(支持Zepto和JQuery)

    一. 效果图 二. 功能说明 1. 支持切换年份,月份. 2. 支持点击选中日期,也可以点击确定选择日期. 三. 使用方法 1. 添加Input 在你的页面中添加Input输入框.可以再html里,也 ...