topcoder srm 610 div1
problem1 link
计算每个格子向上的最大高度。然后每个格子同一行前面的格子以及当前格子作为选取的矩形的最后一行,计算面积并更新答案。
problem2 link
对于两个数据$(x_{1},y_{1}),(x_{2},y_{2})$,若先完成第一个再完成第二个,那么一开始的值$F$需要满足$F\geq max(x_{1}, x_{2}+(x_{1}-y_{1}))$,反过来需要满足$F\geq max(x_{2}, x_{1}+(x_{2}-y_{2}))$。所以若前者更优的话,那么有$max(x_{1}, x_{2}+(x_{1}-y_{1}))<max(x_{2}, x_{1}+(x_{2}-y_{2}))$
由于$x_{1}>y_{1}, x_{2}>y_{2}$,所以等价于$y_{1}<y_{2}$。所以按照$y$升序排序,然后从前向后dp即可。
problem3 link
最后最优值跟$x$的函数关系是多个线段,且这些线段是一个凸函数。如下图的棕色线所示。从后向前扩展每个点。每次扩展相当于把之前的折线从最高处垂直分开然后向两边平移一段距离,然后加上当前点的代价。


code for problem1
#include <string>
#include <vector> class TheMatrix {
public:
int MaxArea(const std::vector<std::string> &board) {
int n = static_cast<int>(board.size());
int m = static_cast<int>(board[0].size());
std::vector<std::vector<int>> h(n, std::vector<int>(m));
int result = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (i == 0 || board[i][j] == board[i - 1][j]) {
h[i][j] = 1;
} else {
h[i][j] = h[i - 1][j] + 1;
}
result = std::max(result, h[i][j]);
int min_h = h[i][j];
for (int k = j - 1; k >= 0 && board[i][k] != board[i][k + 1]; --k) {
min_h = std::min(min_h, h[i][k]);
result = std::max(result, min_h * (j - k + 1));
}
}
}
return result;
}
};
code for problem2
#include <algorithm>
#include <queue>
#include <vector> class AlbertoTheAviator {
public:
int MaximumFlights(int F, const std::vector<int> &duration,
const std::vector<int> &refuel) {
int n = static_cast<int>(duration.size());
std::vector<int> indices(n);
for (int i = 0; i < n; ++i) {
indices[i] = i;
}
std::sort(indices.begin(), indices.end(),
[&](int l, int r) { return refuel[l] > refuel[r]; });
std::vector<std::vector<int>> f(n, std::vector<int>(F + 1));
for (int i = duration[indices[n - 1]]; i <= F; ++i) {
f[n - 1][i] = 1;
}
for (int i = n - 2; i >= 0; --i) {
for (int j = 1; j <= F; ++j) {
f[i][j] = f[i + 1][j];
if (j >= duration[indices[i]]) {
f[i][j] = std::max(
f[i][j],
1 + f[i + 1][j - duration[indices[i]] + refuel[indices[i]]]);
}
}
}
return f[0][F];
}
};
code for problem3
import java.math.*;
import java.util.*; public class MiningGoldHard {
public int GetMaximumGold(int n, int m, int[] event_i, int[] event_j, int[] event_di, int[] event_dj) {
return Solve(n, event_i, event_di) + Solve(m, event_j, event_dj);
} int Solve(int N, int[] e, int[] d) {
int m = e.length;
List<Point> ends = new ArrayList<Point>();
ends.add(new Point(0, N - e[m - 1]));
ends.add(new Point(e[m - 1], N));
ends.add(new Point(N, e[m - 1]));
for (int i = m - 2; i >= 0; -- i) {
List<Point> newEnds = new ArrayList <Point>();
if (d[i] > 0) {
int low = 0;
while (low + 1 < ends.size() && ends.get(low).y < ends.get(low + 1).y) {
++low;
}
for (int j = 0; j <= low; ++ j) {
Point p = ends.get(j);
newEnds.add(new Point(p.x - d[i], p.y));
}
for (int j = low; j < ends.size(); ++ j) {
Point p = ends.get(j);
newEnds.add(new Point(p.x + d[i], p.y));
}
ends = newEnds;
}
newEnds = new ArrayList<Point>();
for (int j = 0; j < ends.size(); ++ j) {
if ((j + 1 < ends.size() && ends.get(j + 1).x < 0) || (j > 0 && ends.get(j - 1).x > N)) {
continue;
}
Point p = ends.get(j);
newEnds.add(new Point(p.x, p.y + N - Math.abs(p.x - e[i])));
if (p.x < e[i] && j + 1 < ends.size() && e[i] < ends.get(j + 1).x) {
Point q = ends.get(j + 1);
newEnds.add(new Point(e[i], N + p.y + (q.y - p.y) * (e[i] - p.x) / (q.x - p.x)));
}
}
ends = newEnds;
}
int result = 0;;
for (Point end : ends) {
if (0 <= end.x && end.x <= N) {
result = Math.max(result, (int)end.y);
}
}
return result;
} class Point {
Point(long x, long y) {
this.x = x;
this.y = y;
}
long x, y;
}
}
topcoder srm 610 div1的更多相关文章
- Topcoder SRM 643 Div1 250<peter_pan>
Topcoder SRM 643 Div1 250 Problem 给一个整数N,再给一个vector<long long>v; N可以表示成若干个素数的乘积,N=p0*p1*p2*... ...
- Topcoder Srm 726 Div1 Hard
Topcoder Srm 726 Div1 Hard 解题思路: 问题可以看做一个二分图,左边一个点向右边一段区间连边,匹配了左边一个点就能获得对应的权值,最大化所得到的权值的和. 然后可以证明一个结 ...
- topcoder srm 714 div1
problem1 link 倒着想.每次添加一个右括号再添加一个左括号,直到还原.那么每次的右括号的选择范围为当前左括号后面的右括号减去后面已经使用的右括号. problem2 link 令$h(x) ...
- topcoder srm 738 div1 FindThePerfectTriangle(枚举)
Problem Statement You are given the ints perimeter and area. Your task is to find a triangle wi ...
- Topcoder SRM 602 div1题解
打卡- Easy(250pts): 题目大意:rating2200及以上和2200以下的颜色是不一样的(我就是属于那个颜色比较菜的),有个人初始rating为X,然后每一场比赛他的rating如果增加 ...
- topcoder srm 610
div1 250pt: 题意:100*100的01矩阵,找出来面积最大的“类似国际象棋棋盘”的子矩阵. 解法:枚举矩阵宽(水平方向)的起点和终点,然后利用尺取法来找到每个固定宽度下的最大矩阵,不断更新 ...
- Topcoder SRM 627 div1 HappyLettersDiv1 : 字符串
Problem Statement The Happy Letter game is played as follows: At the beginning, several players ...
- topcoder SRM 610 DIV2 TheMatrix
题目的意思是给一个01的字符串数组,让你去求解满足棋盘条件的最大棋盘 棋盘的条件是: 相邻元素的值不能相同 此题有点像求全1的最大子矩阵,当时求全1的最大子矩阵是用直方图求解的 本题可以利用直方图求解 ...
- topcoder SRM 610 DIV2 DivideByZero
题目的意思是给你一组数,然后不断的进行除法(注意是大数除以小数),然后将得到的结果加入这组数种然后继续进行除法, 直到没有新添加的数为止 此题按照提议模拟即可 注意要保持元素的不同 int Count ...
随机推荐
- CListCtrl颜色设置
动态改变listctrl 单元格背景及文字颜色 m_listshow.InsertColumn( 0, "ID", LVCFMT_LEFT, 40 );//插入列 m_listsh ...
- Python的基本语法1
一.python的基本数据类型 (1)6种基本数据类型 1.数字类型 int 整数,2,0,-4等 float 浮点数,如1.2,-0.3等 bool 布尔类型,True,False complex ...
- csrf jsonp
网站b中包含向网站a发送的请求,那么网站b就会获得网站a的cookie,网站a登录了则网站b的cookie中会有网站a的sessionid,此时如果网站a对外提供需要sessionid的jsonp接口 ...
- .net拼接json字符串
{ while (reader.Read()) { if (reader.HasRows) { JSONstring += "{"; JSONstring += "\&q ...
- 如何查看正在执行sql的语句及其父语句调用?如何查看正在执行SQL的具体参数值与执行计划?
---SQL Server查询正在执行的SQL语句及执行计划 select ds.session_id,dr.start_time,db_name(dr.database_id),dr.blockin ...
- 安装rosetta2016时出现git@172.16.25.11s password: \r\nPermission denied错误,解决方法。
当在source目录执行 ./external/scons-local/scons.py -j8 mode=release bin 时,报错 git@.11s password: \r\nPermis ...
- 《linux就该这么学》第十五节课:第14,15章,dhcp服务和邮件系统
(借鉴请改动) 13章收尾 13.6.分离解析技术 1.在主配置文件中改两个any 2.编辑区域配置文件,写入acl,使用match匹配 ...
- 1231: ykc买零食
1231: ykc买零食时间限制: 1 Sec 内存限制: 128 MB 题目描述 ykc的班级准备举行班级聚会,而身为生活委员的ykc要为此准备好零食,这天,ykc来到了学校的新起点超市,在转了3 ...
- Python学习笔记(Ⅱ)——循环/选择/函数
一.循环结构 python中提供了for循环和while循环两种操作,没有do……while语句. 1.for循环: 与其他语言中for循环的常见的写法如for (int i=0;i<10;i+ ...
- 缺陷的背后---LIMIT M,N 分页查找
一.问题发现篇 最近组内做了一次典型缺陷分享时,翻阅2018年的缺陷,找到了一个让我觉得“有料”的bug(别的同事测试发现的),先大致简单的描述下这个问题: 需要实现的功能:从一个DB库同步某一段时间 ...