TinaCristal's Blog


  • Home

  • Tags

  • Categories

  • Archives

  • Search

201412-4 最优灌溉

Posted on 2018-12-03 | In ccf认证

问题描述

雷雷承包了很多片麦田,为了灌溉这些麦田,雷雷在第一个麦田挖了一口很深的水井,所有的麦田都从这口井来引水灌溉。
  为了灌溉,雷雷需要建立一些水渠,以连接水井和麦田,雷雷也可以利用部分麦田作为“中转站”,利用水渠连接不同的麦田,这样只要一片麦田能被灌溉,则与其连接的麦田也能被灌溉。

现在雷雷知道哪些麦田之间可以建设水渠和建设每个水渠所需要的费用(注意不是所有麦田之间都可以建立水渠)。请问灌溉所有麦田最少需要多少费用来修建水渠。

Read more »

leetcode 863. All Nodes Distance K in Binary Tree

Posted on 2018-12-03

We are given a binary tree (with root node root), a target node, and an integer value K.

Return a list of the values of all nodes that have a distance K from the target node. The answer can be returned in any order.

Example 1:

Input: root = [3,5,1,6,2,0,8,null,null,7,4], target = 5, K = 2

Output: [7,4,1]

Read more »

leetcode 547. Friend Circles

Posted on 2018-12-03

There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a direct friend of B, and B is a direct friend of C, then A is an indirect friend of C. And we defined a friend circle is a group of students who are direct or indirect friends.

Read more »

leetcode684. Redundant Connection

Posted on 2018-12-03

In this problem, a tree is an undirected graph that is connected and has no cycles.

The given input is a graph that started as a tree with N nodes (with distinct values 1, 2, …, N), with one additional edge added. The added edge has two different vertices chosen from 1 to N, and was not an edge that already existed.

Read more »

Leetcode 882. Reachable Nodes In Subdivided Graph

Posted on 2018-12-02 | In leetcode

Starting with an undirected graph (the “original graph”) with nodes from 0 to N-1, subdivisions are made to some of the edges.

The graph is given as follows: edges[k] is a list of integer pairs (i, j, n) such that (i, j) is an edge of the original graph,

Read more »

prim求最小生成树

Posted on 2018-12-02 | In leetcode

flag[i]=true表明 顶点i 已加入最小生成树
close 存放最后的相关的最小权值

Read more »

Leetcode 934. Shortest Bridge

Posted on 2018-12-02 | In leetcode

In a given 2D binary array A, there are two islands. (An island is a 4-directionally connected group of 1s not connected to any other 1s.)

Now, we may change 0s to 1s so as to connect the two islands together to form 1 island.

Return the smallest number of 0s that must be flipped. (It is guaranteed that the answer is at least 1.)

Read more »

最长公共子序列LCS

Posted on 2018-12-02 | In c++

二维数组c[][]记录最长公共子序列的长度,b[][]记录最长子序列的来源
c[][]右下角的值即为最长子序列的长度

Read more »

ccf 201609-4交通规划

Posted on 2018-12-01

问题描述
  G国国王来中国参观后,被中国的高速铁路深深的震撼,决定为自己的国家也建设一个高速铁路系统。
  建设高速铁路投入非常大,为了节约建设成本,G国国王决定不新建铁路,而是将已有的铁路改造成高速铁路。现在,请你为G国国王提供一个方案,将现有的一部分铁路改造成高速铁路,使得任何两个城市间都可以通过高速铁路到达,而且从所有城市乘坐高速铁路到首都的最短路程和原来一样长。请你告诉G国国王在这些条件下最少要改造多长的铁路。

Read more »

Dijkstra算法

Posted on 2018-12-01

求单源最短路径
dis 保存第i点到源点的最短距离

Read more »
1…192021…45

TinaCristal

443 posts
57 categories
55 tags
GitHub E-Mail
© 2020 TinaCristal
Powered by Hexo
|
Theme — NexT.Mist v5.1.4