- 博客(223)
- 收藏
- 关注
转载 博客变迁通知
我已经建立一个基于Hexo的gitbub.io个人博客:https://pjck.github.io今后关于ACM题(C++版)的总结在这个新博客更新,这个博客园的博客随缘更新。转载于:https://www.cnblogs.com/Weixu-Liu/p/11204726.html...
2019-07-18 06:01:00
238
转载 (欧拉回路 并查集 别犯傻逼的错了) 7:欧拉回路 OpenJudge 数据结构与算法MOOC / 第七章 图 练习题(Excercise for chapter7 graphs)...
7:欧拉回路http://dsalgo.openjudge.cn/graph/7/描述欧拉回路是指不令笔离开纸面,可画过图中每条边仅一次,且可以回到起点的一条回路给定一个无向图,请判断该图是否存在欧拉回路输入输入数据包含若干测试用例每个测试用例的第一行是两个正整数,分别表示图的节点数N(1 < N < 1000)和边数M随后的M行对应M条边,每行有...
2019-05-24 21:45:00
335
转载 (并查集) HDU 1856 More is better
Problem DescriptionMr Wang wants some boys to help him with a project. Because the project is rather complex,the more boys come, the better it will be. Of course there are certain requirements...
2019-05-22 21:29:00
239
转载 (并查集 不太会) HDU 1272 小希的迷宫
Problem Description上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走。但是她设计迷宫的思路不一样,首先她认为所有的通道都应该是双向连通的,就是说如果有一个通道连通了房间A和B,那么既可以通过它从房间A走到房间B,也可以通过它从房间B走到房间A,为了提高难度,小希希望任意两个房间有且仅有一条路径可以相通(除非走了...
2019-05-22 21:03:00
195
转载 (并查集 注意别再犯傻逼的错了) HDU 1213 How Many Tables
Problem DescriptionToday is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius wants to know how many tables he needs at least. You have to notice that not all the ...
2019-05-22 19:52:00
100
转载 (最小生成树 Kruskal算法) 51nod 1212 无向图最小生成树
N个点M条边的无向连通图,每条边有一个权值,求该图的最小生成树。收起输入第1行:2个数N,M中间用空格分隔,N为点的数量,M为边的数量。(2 <= N <= 1000, 1 <= M <= 50000)第2 - M + 1行:每行3个数S E W,分别表示M条边的2个顶点及权值。(1 <= S, E <...
2019-05-21 17:29:00
184
转载 (并查集) HDU 1232 畅通工程
Problem Description某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇。省政府“畅通工程”的目标是使全省任何两个城镇间都可以实现交通(但不一定有直接的道路相连,只要互相间接通过道路可达即可)。问最少还需要建设多少条道路?Input测试输入包含若干测试用例。每个测试用例的第1行给出两个正整数,分别是城镇数目N ( &l...
2019-05-21 11:34:00
81
转载 (最小生成树 Prim) HDU 1233 还是畅通工程
Problem Description某省调查乡村交通状况,得到的统计表中列出了任意两村庄间的距离。省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可),并要求铺设的公路总长度为最小。请计算最小的公路总长度。Input测试输入包含若干测试用例。每个测试用例的第1行给出村庄数目N ( < 10...
2019-05-21 10:29:00
91
转载 (最小生成树 Prim算法) HDU 1863 畅通工程
Problem Description省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可)。经过调查评估,得到的统计表中列出了有可能建设公路的若干条道路的成本。现请你编写程序,计算出全省畅通需要的最低成本。Input测试输入包含若干测试用例。每个测试用例的第1行给出评估的道路条数 N、村庄数目M ...
2019-05-21 09:58:00
128
转载 (总结) 关于Dijkstra的一些看法
1)Dijkstra算法只能适用于权为正的图,有向图和无向图都可以用。2)Dijkstra算法在权为正的图中,如果图恰好是环,那Dijkstra算法也能用,还可以输出最短路。3)Dijkstra算法的本质是贪心,但是,这个可以求出最优解。它和Prim算法是不同的,尽管它们的在核心代码上是基本相似的,但是仍有一些不同的地方。3)面对存在负权的图中,Dijkstra不能用了,因为...
2019-05-20 20:27:00
587
转载 (Dijkstra 输出路径) HDU 1874 畅通工程续
Problem Description某省自从实行了很多年的畅通工程计划后,终于修建了很多路。不过路多了也不好,每次要从一个城镇到另一个城镇时,都有许多种道路方案可以选择,而某些方案要比另一些方案行走的距离要短很多。这让行人很困扰。现在,已知起点和终点,请你计算出要从起点到终点,最短需要行走多少距离。Input本题目包含多组数据,请处理到文件结束。每组数据第一行包...
2019-05-20 20:22:00
98
转载 (Dijkstra 最短路) leetcode 743. Network Delay Time
There areNnetwork nodes, labelled1toN.Giventimes, a list of travel times asdirectededgestimes[i] = (u, v, w), whereuis the source node,vis the target node, andwis the time it tak...
2019-05-20 16:05:00
165
转载 (欧拉图 并查集 图论) 2922. kotori和旅游
【题目描述】kotori有一个目标,要旅游遍全日本。可惜日本太大了,她没有足够的经费。于是kotori计划游览n个地区。她从音乃木坂学院出发,希望把每条线路都走一遍,最后回到音乃木坂学院。她认为走同一条路是愚蠢的,因此在规划旅游线路的时候不能在同一条路上经历两次。n个地区之间共有m条线路。kotori想知道她是否能找到一个完美的规划方案?(注:两个地区之间不保证只有一...
2019-05-19 18:17:00
108
转载 (欧拉图 并查集 图论) nyoj 42-一笔画问题
题目描述:zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下来。规定,所有的边都只能画一次,不能重复画。输入描述:第一行只有一个正整数N(N<=10)表示测试数据的组数。每组测试数据的第一行有两个正整数P,Q(P<=1000,Q<=2000),分别表示这...
2019-05-19 18:00:00
222
转载 (贪心 set 字符串) 2924. kotori和服装设计
【问题描述】kotori是μ's的服装设计担当。她有一个技能,是把一块布料的颜色变成另一个颜色,消耗k点魔法值。已知一件衣服的奇异度取决于这件衣服颜色的种类。颜色种类为1时,奇异度为1。颜色种类为2时,奇异度为3。颜色种类不小于3时,奇异度为10。一件衣服由很多块布料编织而成。kotori不能增加或减少布料数量,但可以消耗k点魔法值改变某块布料的颜色。koto...
2019-05-18 21:41:00
102
转载 (BFS 图的遍历) 2906. kotori和迷宫
【问题描述】kotori在一个n*m迷宫里,迷宫的最外层被岩浆淹没,无法涉足,迷宫内有k个出口。kotori只能上下左右四个方向移动。她想知道有多少出口是她能到达的,最近的出口离她有多远?【输入】第一行为两个整数n和m,代表迷宫的行和列数(1≤n,m≤30)后面紧跟着n行长度为m的字符串来描述迷宫。'k'代表kotori开始的位置,'.'代表道路,'*'代表墙壁,...
2019-05-17 22:40:00
640
转载 (图论基础题) leetcode 997. Find the Town Judge
In a town, there areNpeople labelled from1toN. There is a rumor that one of these people is secretly the town judge.If thetown judge exists, then:The town judge trusts nobody.Every...
2019-05-17 19:19:00
140
转载 (BFS DFS 并查集) leetcode 547. Friend Circles
There areNstudents in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is adirectfriend of B, and B is adirectfriend of C, t...
2019-05-17 16:27:00
107
转载 (BFS DFS 图的遍历) leetcode 841. Keys and Rooms
There areNrooms and you start in room0. Each room has a distinct number in0, 1, 2, ..., N-1, and each room may havesome keys to access the next room.Formally, each roomihas a list of k...
2019-05-17 09:56:00
121
转载 (BFS DFS 图的遍历) leetcode 733. Flood Fill
Animageis represented by a 2-D array of integers, each integer representing the pixel value of the image (from 0 to 65535).Given a coordinate(sr, sc)representing the starting pixel (row and...
2019-05-16 20:58:00
128
转载 (BFS 图的遍历) leetcode 1020. Number of Enclaves
Given a 2D arrayA, each cell is 0 (representing sea) or 1 (representing land)A move consists of walking from one land square 4-directionally to another land square, or off the boundary of the ...
2019-05-15 21:19:00
106
转载 (BFS 输出路径 pair)
迷宫问题Time Limit:1000MSMemory Limit:65536KTotal Submissions:41913Accepted:23240Description定义一个二维数组:int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0,...
2019-05-15 13:08:00
60
转载 (DFS BFS 图的遍历) leetcode 695. Max Area of Island
Given a non-empty 2D arraygridof 0's and 1's, anislandis a group of1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are s...
2019-05-15 08:59:00
102
转载 (DP 线性DP) leetcode 338. Counting Bits
Given a non negative integer numbernum. For every numbersiin the range0 ≤ i ≤ numcalculate the number of 1's in their binary representation and return them as an array.Example 1:Input: 2...
2019-05-14 22:33:00
96
转载 (DP 暂时不会) leetcode 343. Integer Break
Given a positive integern, break it into the sum ofat leasttwo positive integers and maximize the product of those integers. Return the maximum product you can get.Example 1:Input: 2Ou...
2019-05-14 21:51:00
60
转载 (DP LIS) leetcode 646. Maximum Length of Pair Chain
You are givennpairs of numbers. In every pair, the first number is always smaller than the second number.Now, we define a pair(c, d)can follow another pair(a, b)if and only ifb < c. C...
2019-05-10 21:15:00
89
转载 (DP LIS) leetcode 300. Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence.Example:Input: [10,9,2,5,3,7,101,18]Output: 4 Explanation: The longest increasing subsequence is [2,...
2019-05-10 21:01:00
74
转载 (DP 入门) leetcode 120. Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4],...
2019-05-10 19:19:00
75
转载 (DP 线性DP) leetcode 152. Maximum Product Subarray
Given an integer arraynums, find the contiguous subarray within an array (containing at least one number) which has the largest product.Example 1:Input: [2,3,-2,4]Output: 6Explanation:[...
2019-05-10 19:03:00
69
转载 (DP 线性DP) leetcode 221. Maximal Square
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.Example:Input: 1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0Output: 4=...
2019-05-10 12:30:00
97
转载 (DP 线性DP 递推) leetcode 64. Minimum Path Sum
Given amxngrid filled with non-negative numbers, find a path from top left to bottom right whichminimizesthe sum of all numbers along its path.Note:You can only move either down or right...
2019-05-10 09:39:00
73
转载 (DP 线性DP 递推) leetcode 63. Unique Paths II
A robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach t...
2019-05-10 09:35:00
107
转载 (DP 线性DP 递推) leetcode 62. Unique Paths
A robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach t...
2019-05-10 09:31:00
84
转载 (DP 背包) leetcode 198. House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent ...
2019-05-09 19:57:00
73
转载 (贪心 复习) leetcode 1007. Minimum Domino Rotations For Equal Row
In a row of dominoes,A[i]andB[i]represent the top and bottom halves of thei-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)We may rotate thei...
2019-05-07 13:06:00
113
转载 (贪心) leetcode 452. Minimum Number of Arrows to Burst Balloons
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of the horizontal diameter. Since it's horizontal, y-co...
2019-05-07 11:36:00
64
转载 (字符串 栈) leetcode 921. Minimum Add to Make Parentheses Valid
Given a stringSof'('and')'parentheses, we add the minimum number of parentheses ('('or')', and in any positions ) so that the resulting parentheses string is valid.Formally, a parenthe...
2019-05-06 22:19:00
104
转载 (贪心 优先队列) leetcode1005. Maximize Sum Of Array After K Negations
Given an arrayAof integers, wemustmodify the array in the following way: we choose aniand replaceA[i]with-A[i], and we repeat this processKtimes in total. (We may choose the same inde...
2019-05-06 22:08:00
125
转载 (贪心) leetcode 122. Best Time to Buy and Sell Stock II
Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., b...
2019-05-06 21:32:00
114
转载 (贪心) 944. Delete Columns to Make Sorted
We are given an arrayAofNlowercase letter strings, all of the same length.Now, we may choose any set of deletion indices, and for each string, we delete all the characters in those indices....
2019-05-06 21:16:00
73
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人