UVa 10755 Garbage Heap (暴力+前缀和)
题意:有个长方体由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 (暴力+前缀和)的更多相关文章
- 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这一段的 ...
- UVA.12716 GCD XOR (暴力枚举 数论GCD)
UVA.12716 GCD XOR (暴力枚举 数论GCD) 题意分析 题意比较简单,求[1,n]范围内的整数队a,b(a<=b)的个数,使得 gcd(a,b) = a XOR b. 前置技能 ...
- UVA.10305 Maximum Product (暴力)
UVA.10305 Maximum Product (暴力) 题意分析 直接枚举起点和重点,然后算出来存到数组里面,sort然后取最大值即可. 代码总览 #include <iostream&g ...
- uva 725 Division(暴力模拟)
Division 紫书入门级别的暴力,可我还是写了好长时间 = = [题目链接]uva 725 [题目类型]化简暴力 &题解: 首先要看懂题意,他的意思也就是0~9都只出现一遍,在这2个5位数 ...
- UVA - 1602 Lattice Animals (暴力+同构判定)
题目链接 题意:求能放进w*h的网格中的不同的n连通块个数(通过平移/旋转/翻转后相同的算同一种),1<=n<=10,1<=w,h<=n. 刘汝佳的题真是一道比一道让人自闭.. ...
- [暴力+前缀和]2019牛客暑期多校训练营(第六场)Upgrading Technology
链接:https://ac.nowcoder.com/acm/contest/886/J来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262144K,其他语言52428 ...
- UVA 253 Cube painting(暴力打表)
Cube painting Problem Description: We have a machine for painting cubes. It is supplied with three d ...
- Uva 10167 - Birthday Cake 暴力枚举 随机
Problem G. Birthday Cake Background Lucy and Lily are twins. Today is their birthday. Mother buys ...
随机推荐
- android自己定义渐变进度条
项目中须要用到一个弧形渐变的进度条,通过android自带是不能实现的.我是没有找到实现的方法,有大神知道的能够指点.效果图是以下这种 这是通过继承VIew来绘制出来的,网上也有相似的,可是代码那是相 ...
- Django-model_form
ModelForm a. class Meta: model, # 对应Model的 fields=None, # 字段 exclude=None, # 排除字段 labels=None, # 提示信 ...
- Ipython基础功能
ipython:交互式的python命令行 直接在终端敲命令即可进入 安装:pip install ipython 使用:在终端敲“ipython” 与python解释器的使用方法一致 TAB键自动补 ...
- App性能优化浅谈
前言 前段时间给公司的小伙伴们进行了关于app性能优化的技术分享.这里我稍微整理一下也给大家分享一下.关于性能优化这个话题非常大,涉及面能够非常广,也能够非常深入.本人能力有限,不会给大家讲特别难懂, ...
- hessian实战1
服务端: 1.新建MAVEN HessianServer 项目 2.新建接口 Basic public interface Basic { String hello(String name); Str ...
- Spring Boot外部化配置实战解析
一.流程分析 1.1 入口程序 在 SpringApplication#run(String... args) 方法中,外部化配置关键流程分为以下四步 public ConfigurableAppli ...
- 《Android Studio有用指南》7.1 AndroidStudio代码检查工具概述
本文节选自<Android Studio有用指南> 作者: 毕小朋 博客: http://blog.csdn.net/wirelessqa 眼下本书已上传到百度阅读, 在百度中搜索[Anr ...
- Android笔记之dp与px之间的转换以及LayoutParams
dp与px之间的转换公式 px = dp * (dpi / 160) dp = px / (dpi / 160) 其中dpi的获取方式如下 private void getDpi() { Displa ...
- html5 canvas基本用法
通过对canvas的初步了解,经过几天的总结,吧canvas的基本用法总结如下:方便以后查阅 <!doctype html> <html> <head> <m ...
- Redis相关的内核参数解释与设置
参数 somaxconn /proc/sys/net/core/somaxconn 对于TCP连接,Client和Server连接需要三次握手来建立连接,Server端监听状态会由LISTEN切换为E ...