ural 1147. Shaping Regions
1147. Shaping Regions
Memory limit: 64 MB
Input
Output
Sample
input | output |
---|---|
20 20 3 |
1 91 |
/**
Create By yzx - stupidboy
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair inline int Getint()
{
int Ret = ;
char Ch = ' ';
bool Flag = ;
while(!(Ch >= '' && Ch <= ''))
{
if(Ch == '-') Flag ^= ;
Ch = getchar();
}
while(Ch >= '' && Ch <= '')
{
Ret = Ret * + Ch - '';
Ch = getchar();
}
return Flag ? -Ret : Ret;
} const int N = , M = ;
struct Rectangle
{
int lx, rx, uy, dy, color;
inline void Read()
{
scanf("%d%d%d%d%d", &lx, &dy, &rx, &uy, &color);
}
} arr[N];
int width, height, n;
int ans[M]; inline void Input()
{
scanf("%d%d%d", &width, &height, &n);
for(int i = ; i <= n; i++)
arr[i].Read();
} inline int Work(int lx, int dy, int rx, int uy, int index)
{
if(lx >= rx || dy >= uy) return ;
while(index <= n && (
lx >= arr[index].rx ||
rx <= arr[index].lx ||
dy >= arr[index].uy ||
uy <= arr[index].dy)) index++;
if(index > n) return (rx - lx) * (uy - dy);
int ret = ;
ret += Work(lx, dy, min(rx, arr[index].lx), uy, index + );
lx = max(lx, min(rx, arr[index].lx)); ret += Work(max(lx, arr[index].rx), dy, rx, uy, index + );
rx = min(rx, max(lx, arr[index].rx)); ret += Work(lx, dy, rx, min(uy, arr[index].dy), index + );
dy = min(dy, max(uy, arr[index].dy)); ret += Work(lx, max(dy, arr[index].uy), rx, uy, index + );
uy = min(uy, max(dy, arr[index].uy)); return ret;
} inline void Solve()
{
ans[] = width * height;
for(int i = n; i >= ; i--)
{
int area = Work(arr[i].lx,
arr[i].dy,
arr[i].rx,
arr[i].uy,
i + );
ans[arr[i].color] += area;
ans[] -= area;
} for(int i = ; i < M; i++)
if(ans[i]) printf("%d %d\n", i, ans[i]);
} int main()
{
Input();
Solve();
return ;
}
ural 1147. Shaping Regions的更多相关文章
- ural1147 Shaping Regions
Shaping Regions Time limit: 0.5 secondMemory limit: 64 MB N opaque rectangles (1 ≤ N ≤ 1000) of vari ...
- 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 ...
随机推荐
- NYOJ题目842整除的尾数
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAsUAAAIMCAIAAACSTkYzAAAgAElEQVR4nO3dO3KjzBrG8bMJ5VqIYx ...
- java 缩略图
http://www.cnblogs.com/digdeep/p/4829471.html http://www.jb51.net/article/57648.htm http://blog.csdn ...
- 20.策略者模式(Stragety Pattern)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 在asp.net利用jquery.MultiFile实现多文件上传(转载)
转载地址:http://www.cnblogs.com/scy251147/archive/2010/09/30/1839313.html 官网链接:http://www.fyneworks.com/ ...
- AOJ789 买酒
买酒 Time Limit: 1000 ms Case Time Limit: 1000 ms Memory Limit: 64 MBTotal Submission: 70 Submis ...
- git revert 和 git reset的区别
git revert 撤销 某次操作,此次操作之前和之后的commit和history都会保留,并且把这次撤销 作为一次最新的提交 * git revert HEAD ...
- 攻城狮在路上(肆)How tomcat works(零) 前言说明
最近几篇是关于How tomcat works一书的读书笔记. 通过数个章节逐渐实现一个tomcat的功能. 源码下载地址:http://zhidao.baidu.com/share/7007af0f ...
- windows下Tomcat配置多实例
详情参见tomcat安装目录下RUNNING.txt中Advanced Configuration - Multiple Tomcat Instances部分. 问题源于下面这段tomcat官方文档的 ...
- JavaScript - 引用类型
对象在JavaScript中被称为引用类型的值. 引用类型和传统面向对象设计中的类相似,但实现不同. Object是一个基础类型,其他所有类型都从Object继承了基本的行为. Array类型,Dat ...
- vector的主要操作
vector常用方法 assign() 对Vector中的元素赋值 void assign( input_iterator start, input_iterator end ); // void a ...