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 ...
随机推荐
- [Codeforces 932E]Team Work
Description 题库链接 求 \[\sum_{i=1}^n C(n,i)\times i^k\] \(1\leq n\leq 10^9, 1\leq k\leq 5000\) Solution ...
- awk去重以某列重复的行
[root@localhost cc]# cat 2.txt adc 3 5 a d aa 3 adfa d ba 3 adf 去重第一列重复的行: [root@localhost cc]# cat ...
- npm run build之后生成的dist如何扔到服务器运行(npm run build之后如何本地运行)
运行npm run build之后,会生成一个dist文件夹,里面的目录结构大概是这样的: 生成完的文件我们怎么来运行呢?直接在本地打开inde.html是无法运行的,打包的时候有提示: 构建文件应该 ...
- 【拓扑 && 模板】Kosaraju算法
#include<bits/stdc++.h> using namespace std; ; vector <int> g1[maxn],g2[maxn]; stack < ...
- NSLog演化
使用下面代码打印行号,功能函数,以及要打印的内容 #if DEBUG #define MBLog(format, ...) NSLog((@"%s--[Line:%d]--" fo ...
- POJ 1061 青蛙的约会 扩展欧几里德--解不定方程
青蛙的约会 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 81606 Accepted: 14116 Descripti ...
- 资源在Windows编程中的应用
学习目的 掌握菜单和对话框资源的创建和使用. 编写程序: 设计一个窗口应用程序, 其中有一个VC菜单, 该菜单下有"显示", "隐藏", "退出&qu ...
- 使用DOM解析xml文件
使用DOM解析xml文件 要解析的xml文件如下: <?xml version="1.0" encoding="UTF-8"?> <Langu ...
- CF 827E Rusty String FFT
传送门 如果没有碍事的?的话,判定字符串的循环节直接用KMP的失配数组就可以搞定.现在有了碍事的?,我们就需要考虑更通用的算法. 考虑KMP失配数组判定字符串循环节的本质,发现判定\(k\)是否为字符 ...
- AngularJS学习 之 安装
1. 安装好Node.js 2. 安装好Git 3. 安装好Yeoman 以管理员身份打开cmd 输入 npm install -g yo 回车即可开始安装Yeoman,具体的安装行为最好看官网的介绍 ...