codeforces 424D
题意:给定n,m<=300的矩阵,然后求一个长宽大于2的矩形,使得是从左上角位置开始逆时针绕边框一圈的时间最少。时间的计算是:给定3个数tu,tp, td,路径上数字增加为tu,相等为tp否则为td。
思路:直接预处理出4个数组,然后直接暴力。n4的方法。但是常数小可以4000+ms过。
还有一种n3logn的方法。。
具体是固定右下角,然后枚举右上角,然后通过一个通过地推维护一个前缀,二分查找。。
不过常数肯定比暴力大估计快不了多少。。
code:
#include <bits/stdc++.h>
#define M0(x) memset(x, 0, sizeof(x))
#define repf(i, a, b) for(int i = (a); i <= (b); ++i)
#define repd(i, a, b) for(int i = (a); i >= (b); --i)
using namespace std;
int U[][], D[][], L[][], R[][], a[][];
int n, m;
int tp, tu, td, t; inline int f(const int& a, const int& b){
return a == b ? tp : (a > b ? tu : td);
} void init(){
scanf("%d%d%d", &tp, &tu, &td);
M0(U), M0(D), M0(L), M0(R), M0(a);
repf(i, , n) repf(j, , m) scanf("%d", &a[i][j]);
repf(i, , n) repf(j, , m){
D[i][j] = D[i-][j] + f(a[i][j], a[i-][j]);
R[i][j] = R[i][j-] + f(a[i][j], a[i][j-]);
}
repd(i, n, ) repd(j, m, ){
U[i][j] = U[i+][j] + f(a[i][j], a[i+][j]);
L[i][j] = L[i][j+] + f(a[i][j], a[i][j+]);
}
} void solve(){
int ansd = 0x3fffffff, ans = ;
int lx, ly, rx, ry, d;
int tmp;
for (int x = ; x <= n; ++x)
for (int y = ; y <= m; ++y)
for (int x1 = x + ; x1 <= n; ++x1)
for (int y1 = y + ; y1 <= m; ++y1){
tmp = D[x1][y1] - D[x][y1] + U[x][y] - U[x1][y];
tmp += (R[x][y1] - R[x][y] + L[x1][y] - L[x1][y1]);
d = abs(tmp - t);
if (d < ansd || (d == ansd && tmp < ans)){
lx = x, ly = y;
rx = x1, ry = y1;
ansd = d, ans = tmp;
}
}
// cout <<ans << endl;
printf("%d %d %d %d\n", lx, ly, rx, ry);
} int main(){
// freopen("a.in", "r", stdin);
while (scanf("%d%d%d", &n, &m, &t) != EOF){
init();
solve();
}
return ;
}
codeforces 424D的更多相关文章
- codeforces 424D Biathlon Track
codeforces 424D Biathlon Track 题意 题解 代码 #include<bits/stdc++.h> using namespace std; #define f ...
- CodeForces 424D: ...(二分)
题意:给出一个n*m的矩阵,内有一些数字.当你从一个方格走到另一个方格时,按这两个方格数字的大小,有(升,平,降)三种费用.你需要在矩阵中找到边长大于2的一个矩形,使得按这个矩形顺时针行走一圈的费用, ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
随机推荐
- <a>标签的href和onclick属性
讨论 <a>标签中,href和onclick事件的顺序与冲突问题. 首先明确一点:链接的onclick 事件被先执行,其次是href属性下的动作(页面跳转,或 javascript 伪链接 ...
- java 标识符命名规则
标识符:就是给类,接口,方法,变量等起名字. 组成规则: A:英文字母大小写 B:数字字符 C:$和_ 注意事项: A:不能以数字开头 B:不能是Java中的关键字 C:Java语言严格区分大小写 包 ...
- 使用apache-jMeter出现乱码问题。
服务器字符(utf-8)正常,但是在使用apache-jMeter的时候,得到的数据会乱码.所以我们需要设置jmeter的字符编码.默认为ISO-8859-1. 进入jmeter.bat文件夹,有个j ...
- 第五百八十二天 how can I 坚持
好吧,是我错了,昨天,做好自己就行了,别人怎么样是别人的事,永远保持一颗单纯向上的心. 时间过得真快,明天又周六了.. 睡觉.
- MySQL的数据库无法插入中文是怎么回事?
插入中文就报错: Incorrect string value: '\xE7\x8F\xBD\xE7\x8F\xBA' for column 'name' at row 1 用set names ut ...
- docker进程管理
docker进程管理:http://www.open-open.com/lib/view/open1455412749917.html 写的太好!!!!示例很清楚,很全面!! 我做个summary吧. ...
- 动态生成dropdownlist
<td colspan=" id="td_ddl" runat="server"> </td> 后台代码: #region 动 ...
- VC++双缓冲保持背景不擦除之实现
几天前,我终于克服了C++窗体重绘时的闪烁问题,用到的技巧就是双缓冲.但是怎样保持住已经绘制的图形呢?也就是仿照Windows自带的画图程序一般,动态的做出一条直线.最容易想到的方法是在MouseMo ...
- codevs1230 元素查找
1230 元素查找 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Description 给出n个正整数,然后有m个询问,每 ...
- windows10-桌面图标不见了,资源管理器的桌面中可以看到??
问题描述: 1. 桌面的图标,在桌面上看不到, 但是在通过资源管理器可以看到, 图标仍然在桌面 2. 桌面仍然可以右击, 就是看不见新建或者拷贝到桌面的所有图标 解决方案: Google 后请参考: ...