【白书训练指南】(UVa10755)Garbage Heap
先po代码,之后把我那几个不太明了的知识点讲讲,巩固以下。三维的扫描线算法想要掌握还真是有一定的难度的。
代码
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define FOR(i,s,t) for(int i=(s);i<=(t);++i)
using namespace std;
typedef long long ll;
const ll INF=1ll<<60;
const int maxn=25;
inline void expand(int i, int& b0, int& b1,int& b2)
{
b0=i&1; i>>=1;
b1=i&1; i>>=1;
b2=i&1;
return;
}
inline int sign(int b0,int b1,int b2)
{
return (b0+b1+b2)%2?1:-1;
}
ll heap[maxn][maxn][maxn];
ll sum(int x1,int x2,int y1,int y2,int z1,int z2)
{
int dx=x2-x1+1,dy=y2-y1+1,dz=z2-z1+1;
ll s=0;
for(int i=0;i!=8;++i)
{
int b0,b1,b2;
expand(i,b0,b1,b2);
s-=heap[x2-b0*dx][y2-b1*dy][z2-b2*dz]*sign(b0,b1,b2);
}
return s;
}
int main()
{
int T; cin>>T;
while(T--)
{
memset(heap,0,sizeof(heap));
int a,b,c,b0,b1,b2;
cin>>a>>b>>c;
FOR(i,1,a) FOR(j,1,b) FOR(k,1,c) cin>>heap[i][j][k];
FOR(i,1,a) FOR(j,1,b) FOR(k,1,c) FOR(p,1,7)
{
expand(p,b0,b1,b2);
heap[i][j][k]+=heap[i-b0][j-b1][k-b2]*sign(b0,b1,b2);//?????
}
ll ans=-INF;
FOR(x1,1,a) FOR(x2,x1,a) FOR(y1,1,b) FOR(y2,y1,b)
{
ll tmpM=0;
FOR(z,1,c)
{
ll s=sum(x1,x2,y1,y2,1,z);
ans=max(ans,s-tmpM);
tmpM=min(tmpM,s);
}
}
cout<<ans<<endl;
if(T) cout<<endl;
}
return 0;
}
【白书训练指南】(UVa10755)Garbage Heap的更多相关文章
- uva 10755 - Garbage Heap
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- 【降维解法:最大字段和->最大子矩阵和->最终版最大子长方体和】【UVA10755】Garbage Heap
突然感觉刷完这一套专题后 码力有了质的飞跃,fighting 努力会有结果! 最大字段和是一个很经典的问题 O(n)算法 而对于最大子矩阵和 可以思考一个这样的想法 枚举上下边界i,j把i到j这一段的 ...
- 【UVA11107 训练指南】Life Forms【后缀数组】
题意 输入n(n<=100)个字符串,每个字符串长度<=1000,你的任务是找出一个最长的字符串使得超过一半的字符串都包含这个字符串. 分析 训练指南上后缀数组的一道例题,据说很经典(估计 ...
- 白书P61 - 点集配对问题
白书P61 - 点集配对问题 状压DP #include <iostream> #include <cstdio> #include <cstring> using ...
- 白书P60 - 硬币问题
白书P60 - 硬币问题 完全背包.DP #include <iostream> #include <cstdio> #include <cstring> usin ...
- poj 1961 Period(KMP训练指南例题)
Period Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 11356 Accepted: 5279 Descripti ...
- poj2991 Crane(线段树+集合)白书例题
题目大意:起重机有n节,题目给出要调节的k节,每节调节成x度,求最后底部的起重机的坐标(最顶上的起点为(0,0)). 分析:一开始我看白书,看不懂他那个向量旋转的坐标是怎么来的,翻了很多博客,才发现, ...
- Uva10474-STL水题-白书
白书的一道水题.话说好久没认真做难题了.今天出了排名,所有队伍里倒数第一啊! 代码没什么可说的了. #include <algorithm> #include <cstring> ...
- 算法竞赛入门经典训练指南——UVA 11300 preading the Wealth
A Communist regime is trying to redistribute wealth in a village. They have have decided to sit ever ...
随机推荐
- rc.local 开机自启脚本无法启动
1.看是否rc.local 第一行如果是 #!/bin/sh -e 改成 #!/bin/bash sudo systemctl enable rc-local.service 2.看rc.local的 ...
- (第二场)D Money 【dp\贪心】
题目:https://www.nowcoder.com/acm/contest/140/D 题目描述: White Cloud has built n stores numbered from 1 t ...
- Pyplot教程(深度学习入门3)
源地址:http://matplotlib.org/users/pyplot_tutorial.html .caret, .dropup > .btn > .caret { border- ...
- java从mysql读写数据乱码问题
mysql默认使用latin(ISO-8859-1),而java默认使用unicode编码.因此在JAVA中向MYSQL数据库插入数据时,或者读取数据时,都需要先转换一下编码方式. 1.首先查看数据库 ...
- 关于swing界面label和button的动态设置文字
在引入发送验证码功能后,想让button的文本动态变化,发现如下方法并不能做到: int limitSec=10; while(limitSec>0){ sendyzhm.setEnabled( ...
- flask模板语言,装饰器,路由及配置
1.模板语言jinja2 Flask中默认的模板语言是Jinja2 1.0 模板传参 from flask import Flask,render_template app = Flask(__nam ...
- 【译】为什么要写super(props)
译注: 原文地址 https://overreacted.io/why-do-we-write-super-props/ 正文 我听说Hooks是新的热点.好笑的是,我想通过描述一些关于class组件 ...
- OC中自定义init方法
---恢复内容开始--- 我们知道,在函数中实例化一个对象,大多数会同时进行初始化,如 Person *p =[ [Person alloc]init]; 此时已经进行了初始化,使用init方法,那么 ...
- LeetCode 简单 -二进制求和(105)
给定两个二进制字符串,返回他们的和(用二进制表示). 输入为非空字符串且只包含数字 1 和 0. 示例 1: 输入: a = "11", b = "1" 输出: ...
- 『C++』Temp_2018_12_13_Type
#include <iostream> #include <string> using namespace std; class Object{ public: virtual ...