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 ...
随机推荐
- 跨界!Omi 发布多端统一框架 Omip 打通小程序与 Web 腾讯开源 2月28日
https://mp.weixin.qq.com/s/z5qm-2bHk_BCJAwaodrMIg 跨界!Omi 发布多端统一框架 Omip 打通小程序与 Web 腾讯开源 2月28日
- ASO的效果应该如何去评判,有什么标准可以量化指标
ASO的效果应该如何去评判,有什么标准可以量化指标 以往我们主要会教大家怎么做 ASO 优化,优化中有什么技巧……在掌握ASO优化技巧之后,从执行层面来考虑,就该选择流量平台了. 目前市场上的流量平台 ...
- STREAMING HIVE流过滤 官网例子 注意中间用的py脚本
Simple Example Use Cases MovieLens User Ratings First, create a table with tab-delimited text file f ...
- baiduMap & MapV 简单demo
看到 MapV 的一个demo 的底图比较好看,练练手 MapV demos:https://mapv.baidu.com/examples/ 参考的demo:https://mapv.baidu.c ...
- COSC2309/2347 Semester 1, 2019
Mobile Application DevelopmentCOSC2309/2347 Semester 1, 2019Movie Night PlannerAssignment 1 (20 mark ...
- Exp5 MSF基础应用 20164320 王浩
1. 实践目标 本实践目标是掌握metasploit的基本应用方式,重点常用的三种攻击方式的思路.具体需要完成: 1.1一个主动攻击实践,如ms08_067; (1分) 1.2 一个针对浏览器的攻击, ...
- 关于VMware(虚拟机) 出现错误时处理办法
我们在开发中难免会用到虚拟机.前段时间老有同学问我虚拟机报错解决办法,趁今天有空特随笔. 错误如下图 首先科普下VT是个啥? Intel VirtualTechnology(VT)既“虚拟化技术” V ...
- 使用Eclipse来操作HDFS的文件
一.常用类 1.Configuration Hadoop配置文件的管理类,该类的对象封装了客户端或者服务器的配置(配置集群时,所有的xml文件根节点都是configuration) 创建一个Confi ...
- 大疆2019校招FPGA笔试总结
1.对于同步fifo,每100个cycle可以写入80个数据,每10个cycle可以读出8个数据,fifo的深度至少为? 写时钟频率 w_clk, 读时钟频率 r_clk, 写时钟周期里,每B个时钟周 ...
- python练习题-day17
1.计算n!,例如n=3(计算321=6), 求10! 2.已知一个数列:1.1.2.3.5.8.13.....的规律为从3开始的每一项都等于其前两项的和,这是斐波那契数列.求满足规律的100以内的所 ...