可以化简为求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的更多相关文章

  1. SRM 586 DIV1

    A 考虑都是格点 , 枚举所有y+-0.5就行了. trick是避免正好在y上的点重复统计. class PiecewiseLinearFunction { public: int maximumSo ...

  2. Topcoder SRM 643 Div1 250<peter_pan>

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

  3. Topcoder Srm 726 Div1 Hard

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

  4. 图论 SRM 674 Div1 VampireTree 250

    Problem Statement      You are a genealogist specializing in family trees of vampires. Vampire famil ...

  5. SRM 583 DIV1

    A 裸最短路. class TravelOnMars { public: int minTimes(vector <int>, int, int); }; vector<int> ...

  6. SRM 590 DIV1

    转载请注明出处,谢谢viewmode=contents">http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlov ...

  7. topcoder srm 500 div1

    problem1 link 如果decisions的大小为0,那么每一轮都是$N$个人.答案为0. 否则,如果答案不为0,那么概率最大的一定是一开始票数最多的人.因为这个人每一轮都在可以留下来的人群中 ...

  8. topcoder srm 415 div1

    problem1 link 每次贪心地从crans由大到小地找到一个能搬得动地尽量大地box即可. problem2 link 首先,$hava$可以全部换成钱,然后就是找到一个最小的钱减去自己已有的 ...

  9. topcoder srm 410 div1

    problem1 link 不包含$gridConnections$ 的联通块一定是连在所有包含$gridConnections$的联通块中最大的那一块上. import java.util.*; i ...

随机推荐

  1. jQuery实现图片轮播

    之前有碰到过jQuery实现列表自动滚动,这次的图片轮播在原理上与之相同,只有一些细微的差别,就是需要在图片的右下角显示当前图片的序号,效果如下: 先看一看html代码,以及对应的css代码: < ...

  2. 动态链接库加载出错:cannot restore segment prot after reloc: Permission denied

    在执行可执行程序时,出现动态链接库加载出错:cannot restore segment prot after reloc: Permission denied. 主要是由于Linux 内核中提供的强 ...

  3. JS基础类型和对象,分别是按值传递还是按引用传递?

    在分析这个问题之前,我们需了解什么是按值传递(call by value),什么是按引用传递(call by reference).在计算机科学里,这个部分叫求值策略(Evaluation Strat ...

  4. Spark Streaming揭秘 Day7 再探Job Scheduler

    Spark Streaming揭秘 Day7 再探Job Scheduler 今天,我们对Job Scheduler再进一步深入一下,对一些更加细节的源码进行分析. Job Scheduler启动 在 ...

  5. 不得不知道的Python字符串编码相关的知识

    开发经常会遇到各种字符串编码的问题,例如报错SyntaxError: Non-ASCII character 'ascii' codec can't encode characters in posi ...

  6. The Best Rank (25)(排名算法)

    To evaluate the performance of our first year CS majored students, we consider their grades of three ...

  7. Unity3d读取.csv文件

    原文地址:http://blog.csdn.net/dingkun520wy/article/details/26594991 (一)文件路径 需要把csv文件放在StreamingAssets这个文 ...

  8. java se doc

    J2SE 5.0 Performance White Paper http://www.oracle.com/technetwork/java/5-136747.html Java Tuning Wh ...

  9. Webx常用接口

    最近在学Webx框架, 在了解webx的工作流程后, 必须要会使用自带的接口和类 常用的 Navigator  这个接口中只有两种类型的方法, 及重定向与转发, 一般用在screen包下的类(注意:s ...

  10. hdu 4722 Good Numbers(规律题)

    http://acm.hdu.edu.cn/showproblem.php?pid=4722 [题意]: 找GoodNumbers一个数N,如果它每一个位数字之和可以整除10,那么它就是GoodNum ...