/**题目:删去一个点,然后求出需要增加最小代价的边集合生成连通图思路:prim+最小堆1.之前图中未破坏的边必用,从而把两两之间可互达的点集合 合并成一个点2.求出不同点集合的最短距离,用prim+最小堆求出最小生成树 kruskal1.之前图中未破坏的边必用,全部加到图中2.途中被破坏的边按照边权从小到大的顺序依次加入图中,直到图变为连通图 两个方法的对应一个点的最小生成树的复杂度都是nlogm,第二个方法较好写 优化:1.未破坏的边直接加入图中2.当有n-2条边(当前删去一个点后,图中n-…
在敌人占领之前由城市和公路构成的图是连通图.在敌人占领某个城市之后所有通往这个城市的公路就会被破坏,接下来可能需要修复一些其他被毁坏的公路使得剩下的城市能够互通.修复的代价越大,意味着这个城市越重要.如果剩下的城市无法互通,则说明代价无限大,这个城市至关重要.最后输出的是代价最大的城市序号有序列表.借助并查集和Kruskal算法(最小生成树算法)来解决这个问题. //#include "stdafx.h" #include <iostream> #include <a…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 二分查找 日期 题目地址:https://leetcode.com/problems/first-bad-version/description/ 题目描述 You are a product manager and currently leading a team to develop a new product. Unfortunately, the la…
First Bad Version http://lintcode.com/en/problem/first-bad-version The code base version is an integer and start from 1 to n. One day, someone commit a bad version in the code case, so it caused itself and the following versions are all failed in the…
题意与分析 题意真的很简单,实在不想讲了,简单说下做法吧. 枚举删除每个点,然后求最小生成树,如果这个路已经存在那么边权就是0,否则按照原来的处理,之后求花费,然后判整个图是否联通(并查集有几个root),如果不联通直接硬点花费是INF,然后处理输出答案即可. 一道最小生成树的模板题,比较有学习的意义. 代码 /* * Filename: pat_top_1001.cpp * Date: 2018-11-05 */ #include <bits/stdc++.h> #define INF 0x…
题目链接:http://codeforces.com/problemset/problem/320/B 题目意思:有两种操作:"1 x y"  (x < y) 和 "2 a b" (a ≠ b) . 问对于的"2 a b" 询问,能否从第a行的区间到达第b行的区间(行的数量是以:"1 x y" 来统计的,不包括"2 a b"这些行),当然可以直达,也可以借助某些区间间接到达.假设给定一个区间为 (a,…
1013. Battle Over Cities (25) t is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We must know immediately if we need to repair any other…
[LeetCode]165. Compare Version Numbers 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.me/ 题目地址:https://leetcode.com/problems/compare-version-numbers/description/ 题目描述: Compare two version numbers version1 and vers…
Facebook Hacker Cup 2014 Qualification Round比赛Square Detector题的解题报告.单击这里打开题目链接(国内访问需要那个,你懂的). 原题如下: Square Detector Problem Description You want to write an image detection system that is able to recognize different geometric shapes. In the first ver…
Search in Rotated Sorted Array II Follow up for "LeetCode: Search in Rotated Sorted Array 解题报告":What if duplicates are allowed? Would this affect the run-time complexity? How and why? Write a function to determine if a given target is in the arr…