Matrix
Time Limit: 10 Seconds Memory Limit: 131072 KB
A N*M coordinate plane ((0, 0)~(n, m)). Initially the value of all N*M grids are 0.
An operation T(a, b, h, x, y) is defined as follow:
1. Select the maximum value in the matrix (x, y) ~ (x+a, y+b), suppose the maximum value is max
2. Change all the value in the matrix (x, y) ~ (x+a, y+b) into max+h
After C operations, please output the maximum value in the whole N*M coordinate.
Input
The input consists of several cases.
For each case, the first line consists of three positive integers N , M and C (N ≤ 1000, M ≤ 1000, C ≤ 1000). In the following C lines, each line consists of 5 non-negative number, ai, bi, hi, xi, yi (0 ≤ hi ≤ 10000, 0 ≤ xi < n, 0 ≤ yi < m).
Output
For each case, output the maximum height.
Sample Input
3 2 2
2 1 9 1 1
1 1 2 2 1
Sample Output
11
感受:判断两个矩阵是否相交,考虑一定不相交的情况。若考虑相交条件则是有可能相交。并且呀,不相交对立面不一定是相交啊(好人的对立面不一定是坏人啊,有可能是不好不坏的人啦,世界并不是由二元性组成的呀!)
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
struct Matrix
{
int x1,x2,y1,y2,maxn;
};
Matrix matrix [+];
bool cover(Matrix a,Matrix b)
{
if(a.x1>=b.x2||b.x1>=a.x2) return false;
if(a.y1>=b.y2||b.y1>=a.y2) return false;
return true;
}
int n,m,c;
int x,y,h,a,b;
int main()
{
while(~scanf("%d%d%d",&n,&m,&c))
{
int ans=; memset(matrix,,sizeof(matrix));
for(int i=;i<c;i++)
{
int temp=;
scanf("%d%d%d%d%d",&a,&b,&h,&x,&y);
matrix[i].x1=x;
matrix[i].x2=x+a;
matrix[i].y1=y;
matrix[i].y2=y+b;
//matrix[i].h=h;
for(int j=;j<i;j++)
{
if(cover(matrix[i],matrix[j]))
temp=max(temp,matrix[j].maxn);
}
matrix[i].maxn=temp+h;
ans=max(ans,matrix[i].maxn);
}
printf("%d\n",ans);
} return ;
} //1 2
//1
//1 5
ZOJ3578(Matrix)的更多相关文章
-
angular2系列教程(十一)路由嵌套、路由生命周期、matrix URL notation
今天我们要讲的是ng2的路由的第二部分,包括路由嵌套.路由生命周期等知识点. 例子 例子仍然是上节课的例子:
-
Pramp mock interview (4th practice): Matrix Spiral Print
March 16, 2016 Problem statement:Given a 2D array (matrix) named M, print all items of M in a spiral ...
-
Atitit Data Matrix dm码的原理与特点
Atitit Data Matrix dm码的原理与特点 Datamatrix原名Datacode,由美国国际资料公司(International Data Matrix, 简称ID Matrix)于 ...
-
Android笔记——Matrix
转自:http://www.cnblogs.com/qiengo/archive/2012/06/30/2570874.html#translate Matrix的数学原理 在Android中,如果你 ...
-
通过Matrix进行二维图形仿射变换
Affine Transformation是一种二维坐标到二维坐标之间的线性变换,保持二维图形的"平直性"和"平行性".仿射变换可以通过一系列的原子变换的复合来 ...
-
[LeetCode] Kth Smallest Element in a Sorted Matrix 有序矩阵中第K小的元素
Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth ...
-
[LeetCode] Longest Increasing Path in a Matrix 矩阵中的最长递增路径
Given an integer matrix, find the length of the longest increasing path. From each cell, you can eit ...
-
[LeetCode] Search a 2D Matrix II 搜索一个二维矩阵之二
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...
-
[LeetCode] Search a 2D Matrix 搜索一个二维矩阵
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...
随机推荐
-
discuz!
1. discuz! 安装包下载 http://www.discuz.net/thread-3570835-1-1.html
-
mysql入门语句10条
1,连接数据库服务器 mysql -h host -u root -p xxx(密码) 2,查看所有库 show databases; 3,选库 use 库名 4,查看库下面的表 show ...
-
~0u >;>; 1
~ 逐位求反u 后辍为 定义unsigned类型>>右移如在32系统中,连起来就是 将32位的0取反后 右移一位.也就是 int 的最大值 2147482347
-
WEB相关文件的加载顺序
一. 1.启动一个WEB项目,WEB容器会先去读取它的配置文件web.xml,读取<context-param>和<listener>两个节点. 2.接着,容器创建一个Serv ...
-
shell 括号学习
http://blog.csdn.net/tttyd/article/details/11742241 http://tldp.org/LDP/abs/html/loops1.html
-
[music]&;lt;蔷薇&;gt;
我在虾米音乐听到一首好听的歌曲<蔷薇>,一起来听吧!http://www.xiami.com/song/386109?ref=aother LOFTER:我们的故事 http://us ...
-
深入剖析PE文件
不赖猴的笔记,转载请注明出处. 深入剖析PE文件 PE文件是Win32的原生文件格式.每一个Win32可执行文件都遵循PE文件格式.对PE文件格式的了解可以加深你对Win32系统的深入理解. 一. ...
-
FreeBSD安装桌面环境
安装Xorg cd /usr/ports/x11/xorg-minimal make install clean 或 pkg install xorg-minimal 如果最小化安装xorg-serv ...
-
『Tarjan算法 有向图的强连通分量』
有向图的强连通分量 定义:在有向图\(G\)中,如果两个顶点\(v_i,v_j\)间\((v_i>v_j)\)有一条从\(v_i\)到\(v_j\)的有向路径,同时还有一条从\(v_j\)到\( ...
-
南大算法设计与分析课程复习笔记(3)L3 - Recursion
一.递归方程 按照分治的思想,可以将一个递归的复杂度写成递归方程 一.解递归方程--猜然后证明 该方法又称为代入法,步骤如下: 1.猜解的形式 2.数学归纳法证明正确 例子: 我们假设有如下递归式: ...