可以化简为求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. TransparentBlt函数的使用注意事项

    今天客户需要在软件上需要添加一个自己公司的Logo,要求使用镂空透明的形式展现,本来以为很简单的工作没想到在MFC下这么复杂.Logo为BMP格式,白色背景. 以为和在按钮上显示控件差不多,先导入BI ...

  2. L007-oldboy-mysql-dba-lesson07

    L007-oldboy-mysql-dba-lesson07 [root@web01 ~]# mysqldump -uroot -ptestpassword -A >/root/mysql_ba ...

  3. Jquery 禁用 a 标签 onclick 事件30秒后可用

    <a href="javascript:;" id="sendToTel" >发送短信</a> <script type=&quo ...

  4. jquery + json 操作

    jquery 读取集合对象多是要与json进行解析操作的,以下自己经过多方资料查找,终于有一套自己的方式组合.  1.首先创建web services或一般处理程序,用于显示获取Datatable对象 ...

  5. Hibernate Cascade & Inverse

    Cascade - 修改实体表 Inverse - 修改中间表 http://www.cnblogs.com/amboyna/archive/2008/02/18/1072260.html 1.到底在 ...

  6. 解决mac下eclipse字体模糊

    在eclipse.app右键,单击“显示包内容”,如下图: 2.找到"info.plist"文件并打开,在文件最后插入配置“<key>NSHighResolutionC ...

  7. SharedPreference 的存取

    1.通过名称来获取指定的SharedPreferences,下面这句代码表示获取名字问hello的SharedPreferences,数据保存在 data/data/package名/shared_p ...

  8. RadComboBox的用法

    AutoPostBack="true",自动回传数据,也就是自动刷新 <telerik:RadComboBox ID="rcbTeacherList" r ...

  9. Beaglebone Back学习四(GPIO实验)

    GPIO Beaglebone Back开发板引出了92个引脚,其中只有65个GPIO口可通过配置使用,由于引脚具有“复用”的特性,大约每个引脚有8种工作模式(Beagle System Refere ...

  10. hdu 5343 MZL's Circle Zhou SAM

    MZL's Circle Zhou 题意:给定两个长度不超过a,b(1 <= |a|,|b| <= 90000),x为a的连续子串,b为y的连续子串(x和y均可以是空串):问x+y形成的不 ...