题意:有个长方体由A*B*C组成,每个废料都有一个价值,要选一个子长方体,使得价值最大。

析:我们暴力枚举上下左右边界,然后用前缀和来快速得到另一个,然后就能得到长方体,每次维护一个最小值,然后差就是最大值。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#define debug() puts("++++");
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1LL << 60;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 20 + 5;
const int mod = 2000;
const int dr[] = {-1, 1, 0, 0};
const int dc[] = {0, 0, 1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int A, B, C;
LL sum[maxn][maxn][maxn]; void solve(int i){
A = i & 1; i >>= 1;
B = i & 1; i >>= 1;
C = i & 1;
} inline int sign(){ return (A + B + C) & 1 ? 1 : -1; } LL getSum(int x1, int x2, int y1, int y2, int z1, int z2){
int dx = x2 - x1 + 1;
int dy = y2 - y1 + 1;
int dz = z2 - z1 + 1; LL ans = 0;
for(int i = 0; i < 8; ++i){
solve(i);
ans -= sum[x2-A*dx][y2-B*dy][z2-C*dz] * sign();
}
return ans;
} int main(){
int T; cin >> T;
while(T--){
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
memset(sum, 0, sizeof sum);
for(int i = 1; i <= a; ++i) for(int j = 1; j <= b; ++j)
for(int k = 1; k <= c; ++k)
scanf("%lld", &sum[i][j][k]); for(int i = 1; i <= a; ++i) for(int j = 1; j <= b; ++j)
for(int k = 1; k <= c; ++k)
for(int x = 1; x < 8; ++x){
solve(x);
sum[i][j][k] += sum[i-A][j-B][k-C] * sign();
} LL ans = -LNF;
for(int x1 = 1; x1 <= a; ++x1) for(int x2 = x1; x2 <= a; ++x2)
for(int y1 = 1; y1 <= b; ++y1) for(int y2 = y1; y2 <= b; ++y2){
LL mmin = 0;
for(int z = 1; z <= c; ++z){
LL s = getSum(x1, x2, y1, y2, 1, z);
ans = max(ans, s - mmin);
mmin = min(mmin, s);
}
} printf("%lld\n", ans);
if(T) putchar('\n');
}
return 0;
}

UVa 10755 Garbage Heap (暴力+前缀和)的更多相关文章

  1. uva 10755 - Garbage Heap

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  2. 【降维解法:最大字段和->最大子矩阵和->最终版最大子长方体和】【UVA10755】Garbage Heap

    突然感觉刷完这一套专题后 码力有了质的飞跃,fighting 努力会有结果! 最大字段和是一个很经典的问题 O(n)算法 而对于最大子矩阵和 可以思考一个这样的想法 枚举上下边界i,j把i到j这一段的 ...

  3. UVA.12716 GCD XOR (暴力枚举 数论GCD)

    UVA.12716 GCD XOR (暴力枚举 数论GCD) 题意分析 题意比较简单,求[1,n]范围内的整数队a,b(a<=b)的个数,使得 gcd(a,b) = a XOR b. 前置技能 ...

  4. UVA.10305 Maximum Product (暴力)

    UVA.10305 Maximum Product (暴力) 题意分析 直接枚举起点和重点,然后算出来存到数组里面,sort然后取最大值即可. 代码总览 #include <iostream&g ...

  5. uva 725 Division(暴力模拟)

    Division 紫书入门级别的暴力,可我还是写了好长时间 = = [题目链接]uva 725 [题目类型]化简暴力 &题解: 首先要看懂题意,他的意思也就是0~9都只出现一遍,在这2个5位数 ...

  6. UVA - 1602 Lattice Animals (暴力+同构判定)

    题目链接 题意:求能放进w*h的网格中的不同的n连通块个数(通过平移/旋转/翻转后相同的算同一种),1<=n<=10,1<=w,h<=n. 刘汝佳的题真是一道比一道让人自闭.. ...

  7. [暴力+前缀和]2019牛客暑期多校训练营(第六场)Upgrading Technology

    链接:https://ac.nowcoder.com/acm/contest/886/J来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262144K,其他语言52428 ...

  8. UVA 253 Cube painting(暴力打表)

    Cube painting Problem Description: We have a machine for painting cubes. It is supplied with three d ...

  9. Uva 10167 - Birthday Cake 暴力枚举 随机

      Problem G. Birthday Cake Background Lucy and Lily are twins. Today is their birthday. Mother buys ...

随机推荐

  1. angularJS 常用插件指令

    长时间没有登入博客园了,今天突然想了想,当初开这个的目的,其实就是为了记录你当下的一个状态和累计一些问题,所以记录这些还是很有意义,毕竟不是什么牛,靠脸又吃不饱的这个年代,需要留下一些东西给自己看也好 ...

  2. ubuntu 单网卡双 ip

    局域网一套物理网络里有两个 ip 段,单网卡设置多 ip 可实现同时访问两个网段. $ cat /etc/network/interfaces # interfaces(5) file used by ...

  3. 05 referer头与防盗链

    像上图中的这个效果,当我们在网页里引用站外图片时,常出现这样的情况. ??? 服务器是怎么样知道,这个图片是在站外被引用的呢? 还有在网站的统计结果,统计用户从何而来,如下图 ??? 统计时,是如何得 ...

  4. LINQ to SQL 语句(1)之 Where

    LINQ to SQL 语句(1)之 Where Where 操作 适用场景:实现过滤,查询等功能. 说明:与 SQL 命令中的 Where 作用相似,都是起到范围限定也就是过滤作用的 ,而判断条 件 ...

  5. 九度OJ 1109:连通图 (最小生成树)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2783 解决:1432 题目描述: 给定一个无向图和其中的所有边,判断这个图是否所有顶点都是连通的. 输入: 每组数据的第一行是两个整数 n ...

  6. Understanding Unicorn and unicorn-worker-killer Unicorn

    We just wrote some new documentation on how Gitlab uses Unicorn and unicorn-worker-killer, available ...

  7. The basic principle of test case 修改引擎

    The basic principle of test case evaluation is that output resulting from running a test case is com ...

  8. Hadoop实战-MapReduce之WordCount(五)

    环境介绍: 主服务器ip:192.168.80.128(master)  NameNode  SecondaryNameNode ResourceManager 从服务器ip:192.168.80.1 ...

  9. Machine Learning in Action(5) SVM算法

    做机器学习的一定对支持向量机(support vector machine-SVM)颇为熟悉,因为在深度学习出现之前,SVM一直霸占着机器学习老大哥的位子.他的理论很优美,各种变种改进版本也很多,比如 ...

  10. Struts action

    <action name="KnowledgeBankManageAction_*" class="knowledgeBankManageAction" ...