Codility -- Number-of-disc-intersections
来源:互联网 发布:淘宝几天自动确认收货 编辑:程序博客网 时间:2024/06/01 08:27
自己的算法是将区间按照start排序,依次看排序后的每个节点,在之后结点的start序列中二分查找当前结点end点的位置,位置差之和即可。
但是下面的算法更简单。
http://blog.csdn.net/caopengcs/article/details/9327069
// you can also use includes, for example:// #include <algorithm>#include <algorithm>using namespace std;int solution(const vector<int> &A) { // write your code here... int n = A.size(), m = n << 1, i, r, d; vector<pair<long long, int> > a; a.resize(m); for (i = m = 0; i < n; ++i) { a[m++] = make_pair(((long long) i) - A[i], -1); a[m++] = make_pair(((long long) i) + A[i], 1); } sort(a.begin(), a.end()); for (i = r = d = 0; i < m; ++i) { if (a[i].second < 0) { if ((r += d++) > 10000000) { return -1; } } else { --d; } } return r; }
- Codility -- Number-of-disc-intersections
- [codility]Number-of-disc-intersections
- Solution of Codility
- [codility]Max-product-of-three
- Solution of NumberOfDiscIntersections by Codility
- codility
- codility
- the solution of CountNonDivisible by Codility
- Interval Intersections
- Counting Intersections
- DISC定义
- Retrieves a list of the write speeds supported by the disc recorder and current media.
- the centos disc was not found in any of your drives
- wrong number of arguments
- arrangement of number
- pku1351 Number of Locks
- multiply of big Number
- Factorial of a number
- 求二个数的最大公约数
- 单机配置MYSQL多实例
- 部署iwebshop,ecshop到Linux服务器
- 『java』java.lang.ClassFormatError: Test (unrecognized ...
- 安卓 ListView 几个重要属性
- Codility -- Number-of-disc-intersections
- SQL Server 横转纵 行转列
- 读取Android账号类型
- Apk/Jar包混淆方法
- 真机上查 /data/data的shared_prefs目录
- php四种基础算法:冒泡,选择,插入和快速排序法
- 没什么可写的就占用点资源吧
- Oracle中查询主键、外键、sequence、表基本信息等
- mvn常用命令