Question:Given a n,m which means the row and column of the 2D matrix and an array of pair A( size k). Originally, the 2D matrix is all 0 which means t...
分类:
其他好文 时间:
2015-07-02 06:36:01
阅读次数:
162
题意:
给出n个线段,在n个线段之间搭桥,给出m个桥的长度,假如满足条件
To reach the goal, Andrewid needs to place a bridge between each pair of adjacent islands. A bridge of length a can be placed between the i-th and the (i?+?1)-th...
分类:
其他好文 时间:
2015-06-30 14:59:41
阅读次数:
141
欢迎加入Scala讨论QQ群212859367,和连乐一起讨论学习!泛型类例子:class Pair[T, S](val first: T, val second: S)泛型函数例子:def getMiddle[T](a: Array[T] = a(a.length / 2))Scala会从调用该方法使用的实际参数来推断出类型。getMiddle(Array("Mary", "had", "a",...
分类:
其他好文 时间:
2015-06-27 09:50:59
阅读次数:
105
Describe an algorithm that takes an unsorted array of axis‐aligned rectangles and returns any pair of rectangles that overlaps, if ...
分类:
其他好文 时间:
2015-06-26 23:37:54
阅读次数:
202
window.getRequest = function (url) { var theRequest = new Array(); if (url.indexOf("?") > -1) { var pair = url.substr(1).spl...
分类:
Web程序 时间:
2015-06-25 11:52:33
阅读次数:
126
用pair作为基本结构保存q和d,在用一个数组vector<pair >来存储输入数据。然后按照等待时间 d 排序,注意用sort排序默认是用first,这里的的first是q,所以要重写一个比较函数,用second排序。
接下来就是贪心算法,用优先队列priority_queue<pair > 存储结果,这里体现了用pair的优点,刚好优先队列中就是first高优先级高。
一个个入队,如果总时间超过了当前限制时间,则把队中花费时间最长的元素(就是q最大的)删掉。...
分类:
其他好文 时间:
2015-06-25 09:03:00
阅读次数:
205
先考虑一个问题,总和为零,那么意味着正数之和与负数之和的绝对值相等,那么所有数的绝对值之和必定是偶数,所以先判断绝对值之和是不是偶数,不是偶数直接无解。
如果是偶数,把绝对值之和除以2就是正数之和,把输入的序列排序,然后从大到小贪心求解。因为排序之后顺序有了变化,所以用了pair存储,first是值,而second是原始序列中的位置,这样排序的时候存储位置的值也是跟着变化,但每个值的原始位置信息还保存完好。...
分类:
其他好文 时间:
2015-06-24 22:40:57
阅读次数:
158
这里要用到桶排序,感觉不太感兴趣,就直接看了网上的做法。C++中vector中的一些常用函数:取容器中的最大最小值min_element(),max_element()。当有必要对一个接受pair参数的函数传递两个值时, make_pair()尤其显得方便。int minAll = *min_ele...
分类:
其他好文 时间:
2015-06-23 19:57:47
阅读次数:
124
接下来我会写一写Scheme的学习笔记。嗯,Scheme是属于小众的语言,但合适用来教学的。
什么是lat,就是遍历list里的每个S-expression,如果发现其中某个不是atom的,则返回false,否则返回true。
(define atom?
(lambda (x)
(and (not (pair? x)) (not (null? x)))))
(defi...
分类:
其他好文 时间:
2015-06-22 22:20:35
阅读次数:
208
S向每头奶牛连边,容量1每个防晒霜向T连边,容量cover每头奶牛向SPF在自己范围内的防晒霜连边,容量inf用线段树优化建图跑最大流即可。#includeconst int N=7010,inf=~0U>>2;struct edge{int t,f;edge*nxt,*pair;}*g[N],*d...
分类:
其他好文 时间:
2015-06-21 21:07:22
阅读次数:
123