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的更多相关文章

  1. Topcoder SRM 643 Div1 250<peter_pan>

    Topcoder SRM 643 Div1 250 Problem 给一个整数N,再给一个vector<long long>v; N可以表示成若干个素数的乘积,N=p0*p1*p2*... ...

  2. Topcoder Srm 726 Div1 Hard

    Topcoder Srm 726 Div1 Hard 解题思路: 问题可以看做一个二分图,左边一个点向右边一段区间连边,匹配了左边一个点就能获得对应的权值,最大化所得到的权值的和. 然后可以证明一个结 ...

  3. topcoder srm 714 div1

    problem1 link 倒着想.每次添加一个右括号再添加一个左括号,直到还原.那么每次的右括号的选择范围为当前左括号后面的右括号减去后面已经使用的右括号. problem2 link 令$h(x) ...

  4. topcoder srm 738 div1 FindThePerfectTriangle(枚举)

    Problem Statement      You are given the ints perimeter and area. Your task is to find a triangle wi ...

  5. Topcoder SRM 602 div1题解

    打卡- Easy(250pts): 题目大意:rating2200及以上和2200以下的颜色是不一样的(我就是属于那个颜色比较菜的),有个人初始rating为X,然后每一场比赛他的rating如果增加 ...

  6. topcoder srm 610

    div1 250pt: 题意:100*100的01矩阵,找出来面积最大的“类似国际象棋棋盘”的子矩阵. 解法:枚举矩阵宽(水平方向)的起点和终点,然后利用尺取法来找到每个固定宽度下的最大矩阵,不断更新 ...

  7. Topcoder SRM 627 div1 HappyLettersDiv1 : 字符串

    Problem Statement      The Happy Letter game is played as follows: At the beginning, several players ...

  8. topcoder SRM 610 DIV2 TheMatrix

    题目的意思是给一个01的字符串数组,让你去求解满足棋盘条件的最大棋盘 棋盘的条件是: 相邻元素的值不能相同 此题有点像求全1的最大子矩阵,当时求全1的最大子矩阵是用直方图求解的 本题可以利用直方图求解 ...

  9. topcoder SRM 610 DIV2 DivideByZero

    题目的意思是给你一组数,然后不断的进行除法(注意是大数除以小数),然后将得到的结果加入这组数种然后继续进行除法, 直到没有新添加的数为止 此题按照提议模拟即可 注意要保持元素的不同 int Count ...

随机推荐

  1. 【Python基础】lpthw - Exercise 45 制作游戏

    作者在本节中给出了 一些风格建议. 一.函数的风格 1. 类里面的函数经常被称作“方法”,但实质上它和函数没什么不同. 2. 使用类的时候,可以用动词而不是名词给函数命名,指明其具体功能,例如list ...

  2. 数据可视化——阿里云解决方案DataV

    数据可视化——阿里云解决方案DataV https://help.aliyun.com/document_detail/53844.html?spm=a2c4g.11186623.6.579.37fd ...

  3. 内置函数-max、min、round、sorted、ord、chr、any、all、dir、eval、exec、map、filter、reduce

    http://www.nnzhp.cn/archives/152 1.max,min,round print(max([3,4.563,3,6,2.5])) #取最大值,可循环参数即可,int类型的, ...

  4. JMeter压测基础(三)——Mysql数据库

    JMeter压测基础(三)——Mysql数据库 环境准备 mysql驱动 JMeter jdbc配置 JMeter jdbc请求 1.下载mysql驱动:mysql-connector-java.ja ...

  5. redis集群及相关的使用

    从redis 3.0之后版本支持redis-cluster集群,Redis-Cluster采用无中心结构,每个节点保存数据和整个集群状态,每个节点都和其他所有节点连接. 1.所有的redis节点彼此互 ...

  6. spring-boot mybatis配置

    接着我们的spring boot项目,spring boot如何使用mybatis访问数据库呢? 个人习惯使用mapper接口和xml配置sql,从pom.xml入手 1.1 添加依赖 <dep ...

  7. python学习笔记1-基础知识

    # 0.输入输出 # print数值型直接输出计算结果 pirnt( + ) # 输出 + = # input输入(可在括号内加提示语句) name = input('please enter you ...

  8. Django---cookie和session

    Django的cookie和session 一.cookie 二.session 回到顶部 一.cookie 1.特点 1. cookie数据保存在客户端,以key-value存储 2. cookie ...

  9. mybatis多参数传递(其中包括数组)

    mapper接口 public void batchDelete(@Param(value = "activityId") Integer activityId, @Param(v ...

  10. svg合并

    假如页面有多个svg图标要加载,多次加载不利,可将多个svg合并为一个加载 如下有两个svg <svg xmlns="http://www.w3.org/2000/svg" ...