ural1147 Shaping Regions
Shaping Regions
Memory limit: 64 MB
Input
Output
Sample
| input | output |
|---|---|
20 20 3 |
1 91 |
分析:经典的覆盖问题,参考http://blog.csdn.net/skyprophet/article/details/4514926,冰块上浮法;
倒序计算,在计算到当前矩形时,看在他上面的矩形有没有重叠的,有就去掉那个部分,一直递归下去即可;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=3e3+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,k,t,ans[maxn];
struct node
{
int x1,x2,y1,y2,c;
node(){}
node(int _x1,int _x2,int _y1,int _y2,int _c)
{
x1=_x1,x2=_x2,y1=_y1,y2=_y2,c=_c;
}
}op[maxn];
int get(node p,int nt)
{
int ans=;
while(nt<=k&&((p.x1>=op[nt].x2)||(p.x2<=op[nt].x1)||(p.y1>=op[nt].y2)||(p.y2<=op[nt].y1)))
nt++;
if(nt>k)return (p.x2-p.x1)*(p.y2-p.y1);
if(p.x1<op[nt].x1)
ans+=get(node(p.x1,op[nt].x1,p.y1,p.y2,op[nt].c),nt+),p.x1=op[nt].x1;
if(p.x2>op[nt].x2)
ans+=get(node(op[nt].x2,p.x2,p.y1,p.y2,op[nt].c),nt+),p.x2=op[nt].x2;
if(p.y1<op[nt].y1)
ans+=get(node(p.x1,p.x2,p.y1,op[nt].y1,op[nt].c),nt+),p.y1=op[nt].y1;
if(p.y2>op[nt].y2)
ans+=get(node(p.x1,p.x2,op[nt].y2,p.y2,op[nt].c),nt+),p.y2=op[nt].y2;
return ans;
}
int main()
{
int i,j;
scanf("%d%d%d",&n,&m,&k);
ans[]=n*m;
rep(i,,k)scanf("%d%d%d%d%d",&op[i].x1,&op[i].y1,&op[i].x2,&op[i].y2,&op[i].c);
for(i=k;i>=;i--)
{
ans[op[i].c]+=(j=get(op[i],i+));
ans[]-=j;
}
rep(i,,)if(ans[i])printf("%d %d\n",i,ans[i]);
//system("Pause");
return ;
}
ural1147 Shaping Regions的更多相关文章
- ural 1147. Shaping Regions
1147. Shaping Regions Time limit: 0.5 secondMemory limit: 64 MB N opaque rectangles (1 ≤ N ≤ 1000) o ...
- Shaping Regions(dfs)
Shaping Regions Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 124 Solved: 39[Submit][Status][Web B ...
- USACO 6.2 Shaping Regions
Shaping Regions N opaque rectangles (1 <= N <= 1000) of various colors are placed on a white s ...
- OI暑假集训游记
莞中OI集训游记 Written BY Jum Leon. I 又是一载夏,本蒟蒻以特长生考入莞中,怀着忐忑的心情到了8月,是集训之际.怀着对算法学习的向往心情被大佬暴虐的一丝恐惧来到了 ...
- USACO 完结的一些感想
其实日期没有那么近啦……只是我偶尔还点进去造成的,导致我没有每一章刷完的纪念日了 但是全刷完是今天啦 讲真,题很锻炼思维能力,USACO保持着一贯猎奇的题目描述,以及尽量不用高级算法就完成的题解……例 ...
- [LeetCode] Surrounded Regions 包围区域
Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A region is captured ...
- 验证LeetCode Surrounded Regions 包围区域的DFS方法
在LeetCode中的Surrounded Regions 包围区域这道题中,我们发现用DFS方法中的最后一个条件必须是j > 1,如下面的红色字体所示,如果写成j > 0的话无法通过OJ ...
- Leetcode: Surrounded regions
Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A region is captured ...
- LEETCODE —— Surrounded Regions
Total Accepted: 43584 Total Submissions: 284350 Difficulty: Medium Given a 2D board containing 'X' a ...
随机推荐
- MFC消息机制
何谓消息.消息处理函数.消息映射?消息简单的说就是指通过输入设备向程序发出指令要执行某个操作.具体的某个操作是你的一系列代码.称为消息处理函数. 在SDK中消息其实非常容易理解,当窗口建立后便会有一个 ...
- 自定义NSOperation
一直在思考,每次异步请求都会创建一个新线程,如果我同时发100个异步请求,这样会导致我的内存爆满,应用程序奔溃,因为iOS对开线程有着约束,不能开很多个线程,这就要求我们必须对异步请求进行控制,我一直 ...
- 关于js中原型链的理解
我们创建的每个函数都有一个prototype(原型)属性,这个属性是一个指针,一个对象.无论什么时候,我们只要创建一个新函数,就会根据一组特定的规则为该函数创建一个prototype属性,这个属性对象 ...
- hdu_1536_S-Nim(DFS_SG博弈)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1536 题意:首先输入K ,表示一个集合的大小 , 之后输入集合, 表示对于这对石子只能去这个集合中的元 ...
- 安卓无法生成R文件原因
原因个人总结出来: 清单文件报错,则无法生成R文件 gen和bin目录可以删除
- 推翻自己和过往,重学自定义View
http://blog.csdn.net/lfdfhl/article/details/51671038 深入探讨Android异步精髓Handler 站在源码的肩膀上全解Scroller工作机制 A ...
- js获取页面的来源页
<html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat=&quo ...
- ENC28j60以太网芯片驱动程序简介
ENC28j60以太网芯片驱动程序简介 ENC28J60 驱动开发要点 enc28J60 和 Arduino (1)——ping通你的Arduino MCU51单片机uIP协议栈+ENC28J60网卡 ...
- 1.2 eclipse使用 :working set
working set可以是相当于文件夹~~有多个project时, 分别存放在不同的 workingset下,可以方便管理 新建或编辑 working set时,需要记住选择project *可参照 ...
- 软件开发常用的linux命令心得(ubuntu为例)
软件开发过程中难免要经常对主机进行配置或者部署等操作,想到一些就写一些了,以后再更新 解压命令: a.如果是tar文件,则直接用 “tar zxvf 文件名”: b.如果是zip文件,用 “unzip ...