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 ...
随机推荐
- java运算符新用法和^新认识
public class Demo1 { public static void main(String[] args) { boolean t = false | true; System.out.p ...
- 隐藏index.php - ThinkPHP完全开发手册 - 3.1
为了更好的实现SEO优化,我们需要隐藏URL地址中的index.php,由于不同的服务器环境配置方法区别较大,apache环境下面的配置我们可以参考5.9 URL重写来实现,就不再多说了,这里大概 ...
- Android SDK Manager国内无法更新的解决方案
万里长城永不倒,千里黄河水滔滔.算了跑题了. 但还是要吐槽这下这个万里长城,感谢 方滨兴 叫兽 给我们净化了互联网,靠!什么&!@#¥ 此处略去一万字. 现在由于GWF,google基本和咱们 ...
- TextBox 绑定到DataTable某一列属性上
将TextBox绑定到DataTable某一列属性上 DataTable dt = GetDataTable() textBox1.DataBindings.Add("Text", ...
- css3选择器一
在HTML中,通过各种各样的属性可以给元素增加很多附加的信息,了解和掌握css3一些的选择器,是很有必要的. 属性选择器示例: <div><a href="xxx.pdf& ...
- spring-cloud-feign案例
主要依赖 <dependencyManagement> <dependencies> <dependency> <groupId>org.springf ...
- Mac OS X 10.10 Yosemite PHP 5.5.14 free type support fix
通过将php将至5.4来勉强支持freetype扩展,不推荐此方法 after upgrading to new Mac OS X Yosemite, i noticed that free type ...
- 【BZOJ 1497】 [NOI2006]最大获利
Description 新的技术正冲击着手机通讯市场,对于各大运营商来说,这既是机遇,更是挑战.THU集团旗下的CS&T通讯公司在新一代通讯技术血战的前夜,需要做太多的准备工作,仅就站址选择一 ...
- sharepoint warmup
/---------------- using System;using System.Collections.Generic; using System.Text;using System.Net; ...
- .net google calendar
https://developers.google.com/gdata/client-cs http://www.codeproject.com/Articles/64474/How-to-Read- ...