SRM 586 DIV1 L1
可以化简为求n条线段的最大覆盖问题,需要注意的是对于实数而言。
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <string.h>
using namespace std; class PiecewiseLinearFunction {
private:
map<int, int> Y2i;
int value[];
public:
int maximumSolutions(vector <int> Y) {
for (int i = ; i < Y.size(); i++) {
Y2i[Y[i]] = ;
}
int no = ;
for (map<int, int>::iterator it = Y2i.begin(); it != Y2i.end(); it++) {
//cout << it->first << endl;
it->second = * no++;
} memset(value, , sizeof(value)); for (int i = ; i < Y.size() - ; i++) {
int d = Y[i + ] - Y[i];
if (d == ) {
return -;
} else {
d = d / abs(d);
int begin = Y2i[Y[i]];
int end = Y2i[Y[i + ]];
while (begin != end) {
value[begin]++;
begin += d;
}
}
}
value[Y2i[Y.back()]]++; int ans = ;
for (int i = ; i < ; i++) {
ans = max(ans, value[i]);
}
return ans;
}
};
SRM 586 DIV1 L1的更多相关文章
- SRM 586 DIV1
A 考虑都是格点 , 枚举所有y+-0.5就行了. trick是避免正好在y上的点重复统计. class PiecewiseLinearFunction { public: int maximumSo ...
- 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 解题思路: 问题可以看做一个二分图,左边一个点向右边一段区间连边,匹配了左边一个点就能获得对应的权值,最大化所得到的权值的和. 然后可以证明一个结 ...
- 图论 SRM 674 Div1 VampireTree 250
Problem Statement You are a genealogist specializing in family trees of vampires. Vampire famil ...
- SRM 583 DIV1
A 裸最短路. class TravelOnMars { public: int minTimes(vector <int>, int, int); }; vector<int> ...
- SRM 590 DIV1
转载请注明出处,谢谢viewmode=contents">http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlov ...
- topcoder srm 500 div1
problem1 link 如果decisions的大小为0,那么每一轮都是$N$个人.答案为0. 否则,如果答案不为0,那么概率最大的一定是一开始票数最多的人.因为这个人每一轮都在可以留下来的人群中 ...
- topcoder srm 415 div1
problem1 link 每次贪心地从crans由大到小地找到一个能搬得动地尽量大地box即可. problem2 link 首先,$hava$可以全部换成钱,然后就是找到一个最小的钱减去自己已有的 ...
- topcoder srm 410 div1
problem1 link 不包含$gridConnections$ 的联通块一定是连在所有包含$gridConnections$的联通块中最大的那一块上. import java.util.*; i ...
随机推荐
- python pil 安装
Ubuntu下 sudo pip install pil 安装PIL可能会出现问题,例如安装完成时显示JPEG support not available 或者 ZLIB (PNG/ZIP) supp ...
- Servlet、Filter 生命周期
Servlet作为JavaEE必须掌握的内容,Struts2通过使用Filter的功能实现了一个MVC的框架.因此掌握这Servlet以及Filter的生命周期显得非常重要. 1. Servlet的生 ...
- automake使用
antuomake 流程图: http://blog.csdn.net/houwei544/article/details/8185916 这个教程不错 https://www.ibm.com/dev ...
- 【C#高级编程(学习与理解)】1.1 C#与.NET的关系
1.C#语言不能孤立使用,而必须和.NET Framework一起考虑.C#编译器专门用于.NET,这表示用C#编写的所有代码总是在.NET Framework中运行. 2.C#就其本身而言只是一种语 ...
- KnockoutJS(2)-监控属性
本节主要涉及到3个内容: 1. 监控属性 Observables (这个用的比较多,但是其本身使用比较简单,唯一需要注意就是,它监控的对象是一个方法,所以取值和设置值的时候容易混淆) 2. 计算属性 ...
- jquery nicescroll 配置参数
jQuery滚动条插件兼容ie6+.手机.ipad http://www.areaaperta.com/nicescroll/ jQuery(function($){ $("#scrollI ...
- 基于api安全性的解决处理方案
api解决用户安全主要采用两种方案: 一.使用token识别用户信息,作为识别用户的凭证 1.为什么使用token? 常规性的pc站点,使用session存储用户登录状态. 即用户登录之后,服务端会生 ...
- Inside Microsoft SQL Server 2008: T-SQL Querying 读书笔记1
(5)SELECT (5-2) DISTINCT (5-3)TOP(<top_specifications>) (5-1)<select_list> (1)FRO ...
- Spark Streaming揭秘 Day8 RDD生命周期研究
Spark Streaming揭秘 Day8 RDD生命周期研究 今天让我们进一步深入SparkStreaming中RDD的运行机制.从完整的生命周期角度来说,有三个问题是需要解决的: RDD到底是怎 ...
- 在emacs里用w3m浏览网页
给w3m配置个~/.emacs老是暴错误,在配置里把这个注掉就OK了;(require 'mime-w3m) ;;支持w3m (add-to-list 'load-path "/usr/sh ...