题意:给定一个n个点m条边的带权有向图,求平均权值最小的回路的平均权值?思路:首先,图中得有环的存在才有解,其次再解决这个最小平均权值为多少。一般这种就是二分猜平均权值了,因为环在哪也难以找出来,还有可能是一条边属于多个环。对于每个猜到的平均值,如果对应环的存在,那么这个环的每条边的权减去这个平均值...
分类:
其他好文 时间:
2015-07-27 18:35:14
阅读次数:
87
Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Follow up:Can you solve it without using extra space?因为f...
分类:
其他好文 时间:
2015-07-26 23:57:57
阅读次数:
213
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?/** * Definition for singly-linked list. *...
分类:
其他好文 时间:
2015-07-26 22:34:52
阅读次数:
163
题意:给定一个n个点m条边的加权有向图,求平均权值最小的回路。
思路:使用二分法求解,对于每一个枚举值mid,判断每条边权值减去mid后有无负圈即可。
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#inc...
分类:
其他好文 时间:
2015-07-26 00:35:48
阅读次数:
140
若同时从一个环的某个点出发,fast指针每次走两步,slow指针每次走一步,则可证明slow指针走回起点时,fast指针也恰好到达起点。两种思路:一、fast指针每次比slow指针多走一步,fast指针想与slow指针同时到达某点,必须超过slow指针一圈,每次多走一步,假设环的节点数为N,则多走一圈需要走N次,此时slow指针恰好走完一圈指向出发点,fast指针亦然;二、fast指针的速度是sl...
分类:
其他好文 时间:
2015-07-22 18:52:18
阅读次数:
109
在使用JSONObject.fromObject的时候,出现“There is a cycle in the hierarchy”异常。意思是出现了死循环,也就是Model之间有循环包含关系;解决办法:使用setCycleDetectionStrategy防止自包含代码:JsonConfig jso...
分类:
Web程序 时间:
2015-07-22 18:11:32
阅读次数:
128
leetcode -Linked List CycleGiven a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?/** * Definitio...
分类:
其他好文 时间:
2015-07-22 12:14:17
阅读次数:
114
2.6 Given a circular linked list, implement an algorithm which returns the node at the beginning of the loop.DEFINITIONCircular linked list: A (corrup...
分类:
其他好文 时间:
2015-07-21 22:00:57
阅读次数:
118
新技能get二分图染色居然可以用来判断奇偶环。。如果能构成二分图,说明没有奇环对于任意二分图,其包含的环一定全部是偶环!(充要可证)可以证明,含有奇数条边的环一定有两个在相同集合内的点有边相连!也就是说——二分图的bfs子树一定不含奇环!下面讨论摘自http://www.cnblogs.com/sa...
分类:
其他好文 时间:
2015-07-19 19:28:04
阅读次数:
147
脏数据检查 != 轮询检查更新谈起angular的脏检查机制(dirty-checking), 常见的误解就是认为: ng是定时轮询去检查model是否变更。其实,ng只有在指定事件触发后,才进入$digest cycle:DOM事件,譬如用户输入文本,点击按钮等。(ng-click)XHR响应事件...
分类:
Web程序 时间:
2015-07-17 22:39:51
阅读次数:
373