codeforces 424D Biathlon Track
codeforces 424D Biathlon Track
题意
题解
代码
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
//---
const int N = 333;
int n, m, t, tp, tu, td;
int x11, y11, x2, y2;
int a[N][N];
ll ans;
ll pre[N][N][4];
inline void upd(ll x, int i, int j, int a, int b) {
if(!ans || abs(x - t) < abs(ans - t)) {
ans = x;
x11 = i;
x2 = j;
y11 = a;
y2 = b;
}
}
inline int calc(int x, int y) {
if(x == y) return tp;
if(x > y) return tu;
return td;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
cin >> n >> m >> t;
cin >> tp >> tu >> td;
rep(i, 1, n+1) rep(j, 1, m+1) cin >> a[i][j];
rep(i, 1, n+1) rep(j, 2, m+1) pre[i][j][0] = pre[i][j-1][0] + calc(a[i][j], a[i][j-1]);
rep(i, 1, n+1) rep(j, 1, m) pre[i][j][2] = pre[i][j-1][2] + calc(a[i][j], a[i][j+1]);
rep(j, 1, m+1) rep(i, 2, n+1) pre[i][j][1] = pre[i-1][j][1] + calc(a[i][j], a[i-1][j]);
rep(j, 1, m+1) rep(i, 1, n) pre[i][j][3] = pre[i-1][j][3] + calc(a[i][j], a[i+1][j]);
rep(i, 1, n+1) rep(j, i+2, n+1) {
set<pair<ll, int> > s;
rep(k, 1, m+1) {
if(k-2>=1) {
int c = k - 2;
ll t = - pre[i][c][0] - pre[j][c-1][2] + pre[j-1][c][3] - pre[i-1][c][3];
s.insert(mp(t, c));
}
if(!s.empty()) {
ll res = pre[i][k][0] + pre[j][k-1][2] + pre[j][k][1] - pre[i][k][1];
ll c = t - res;
auto tmp = s.lower_bound(mp(c, 0));
if(tmp != s.end()) {
upd(res + tmp->fi, i, j, tmp->se, k);
}
if(tmp != s.begin()) {
tmp--;
upd(res + tmp->fi, i, j, tmp->se, k);
}
}
}
}
cout << x11 << " " << y11 << " " << x2 << " " << y2 << endl;
return 0;
}
codeforces 424D Biathlon Track的更多相关文章
- Biathlon Track
Codeforces Round #242 (Div. 2) D:http://codeforces.com/contest/424/problem/D 题意:给你一个n*m的矩阵,每个格子上面有个数 ...
- Codeforces 615C Running Track(DP + Trie树)
题目大概说给两个串,问最少要用多少个第一个串的子串(可以翻转)拼成第二个串. UVa1401,一个道理..dp[i]表示前缀i拼接成功所需最少的子串,利用第一个串所有子串建立的Trie树往前枚举转移. ...
- codeforces 424D
题意:给定n,m<=300的矩阵,然后求一个长宽大于2的矩形,使得是从左上角位置开始逆时针绕边框一圈的时间最少.时间的计算是:给定3个数tu,tp, td,路径上数字增加为tu,相等为tp否则为 ...
- CodeForces 424D: ...(二分)
题意:给出一个n*m的矩阵,内有一些数字.当你从一个方格走到另一个方格时,按这两个方格数字的大小,有(升,平,降)三种费用.你需要在矩阵中找到边长大于2的一个矩形,使得按这个矩形顺时针行走一圈的费用, ...
- Codeforces Round #242 (Div. 2) <A-D>
CF424 A. Squats 题目意思: 有n(n为偶数)个x和X,求最少的变换次数,使得X的个数为n/2,输出变换后的序列. 解题思路: 统计X的个数ans,和n/2比較,少了的话,须要把n/2- ...
- Codeforces Round #338 (Div. 2) C. Running Track dp
C. Running Track 题目连接: http://www.codeforces.com/contest/615/problem/C Description A boy named Ayrat ...
- 【28.57%】【codeforces 615C】 Running Track
time limit per test1 second memory limit per test512 megabytes inputstandard input outputstandard ou ...
- Codeforces Round #313 (Div. 2) C. Gerald's Hexagon 数学
C. Gerald's Hexagon Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/pr ...
- Codeforces Gym 100531I Instruction 构造
Problem I. Instruction 题目连接: http://codeforces.com/gym/100531/attachments Description Ingrid is a he ...
随机推荐
- s11d27 算法
s11d27 算法 一.理论 1.1 时间复杂度和空间复杂度的理论: 1)空间复杂度: 是程序运行所以需要的额外消耗存储空间,一般的递归算法就要有o(n)的空间复杂度了, 简单说就是递归集算时通常是反 ...
- 实现Vue 的 markdown 文档可以在线运行(vue-markdown-run)
闲暇时间我用Vue框架写了一个博客,编辑器是用的markdown文本的形式,介绍性+描述完全能满足我的需求,但是,如果想在线运行我markdown文本中的Vue组件代码,则无法实现了, 于是我就自己写 ...
- Executor、ExecutorService、ThreadPoolExecutor
1.Executor Executor接口中中只有一个方法 执行已提交的Runnable任务对象. ExecutorService pool1 = Executors.newFixedThreadPo ...
- 无法正常下载Nuget 包的问题
引用Nuget 是遇到的问题,再次记录一下. 问题描述:Install-Package : 无法安装程序包“Quartz 3.0.2”.您正在尝试将此程序包安装到某个将“.NETFramework,V ...
- Python标准模块--concurrent.futures 进程池线程池终极用法
concurrent.futures 这个模块是异步调用的机制concurrent.futures 提交任务都是用submitfor + submit 多个任务的提交shutdown 是等效于Pool ...
- 前台提交数据(表单数据、Json数据及上传文件)的类型
MIME (Multipurpose Internet Mail Extensions) 是描述内容类型的互联网标准.Clients use this content type or media ty ...
- angular2.0---服务Service,使用服务进行数据处理
1.创建服务 打开命令窗口,cd到项目目录下,输入 ng g service myData1 回车 创建服务,如下图所示: 这样就成功创建了服务,此时,可以在项目的app文件夹下生成了两个serv ...
- EF_CRUD
- 浅析javascript高阶函数
什么是高阶函数:在数学和计算机科学中,高阶函数是至少满足下列一个条件的函数: 1. 接受一个或多个函数作为输入: 2. 输出一个函数.在数学中它们也叫做算子(运算符)或泛函.微积分中的导数就是常见的例 ...
- OpenGL学习--05--纹理立方体--BMP文件格式详解(转载)
http://blog.csdn.net/o_sun_o/article/details/8351037 BMP文件格式详解 BMP文件格式详解(BMP file format) BMP文件格式,又称 ...