并查集总结
今天总结一下并查集,这个完了之后,寒假学的数据结构基础的模板类的题目差不多就完了,对于模板题,敲上10遍、20遍、30遍,那么模板
就不是模板,就成为了你自己的东西,就好像 A+B 一辈子也忘不了,以后每天敲一遍模板题,加深对模板的理解。
并查集,一般使用的是 数组实现、树实现,其中数组实现时间复杂度较高,树实现也就是分离集合森林 查找、合并的时间复杂度不会...
分类:
其他好文 时间:
2014-06-09 23:14:04
阅读次数:
204
HDU 4324 Triangle LOVE (拓扑排序)
题目大意:
T组测试数据,每组数据一个n表示n个人,接下n*n的矩阵表示这些人之间的关系,输入一定满足若A不喜欢B则B一定喜欢A,且不会出现A和B相互喜欢的情况,问你这些人中是否存在三角恋。
解题思路:
拓扑排序思想很简单,就是找入度为0的点,放入队列,用队列来实现。
拓扑排序后判断是否有环存在,有环必然存在是三角恋。
证明:
假设存在一个n元环
首先,...
分类:
其他好文 时间:
2014-06-08 18:31:38
阅读次数:
241
本题有两个考点:
1 求逆序数的性质
计算逆序数的公式, 一个数arr[i]从前面放到后面,必然会有n-arr[i]-1个数比这个大,那么就有n-arr[i]-1个逆序数增加,同时因为前面少了个arr[i]数,那么就必然有arr[i]个(加上零)数比起小的数失去一个逆序数,总共失去arr[i]个逆序数,所以新的逆序数为增加了n-arr[i]-1-arr[i]个逆序数(当然有可能是减小了,视ar...
分类:
其他好文 时间:
2014-06-08 15:52:20
阅读次数:
275
问题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1495
题目大意:一个瓶子容积s,两个杯子容积分别n,m,并且都没有刻度(不能比对噢!)。相互倒水,求平分的他们的最少倒水次数。
思路:暴力搜索吧。并且求最少,(即最优解),随意上BFS;
思考:状态,转移过程,怎么剪纸。
惨痛的debug,我不解释了。...
分类:
其他好文 时间:
2014-06-08 15:48:26
阅读次数:
234
给出一段数据,然后要更新单个数据,会询问一段数据中的最大值。
又是一道分段树操作。渐渐熟手了。
#pragma once
#include
#include
using namespace std;
class IHateIt_1754_1
{
static const int SIZE = 200001;
int *segTree; //不要使用segTree[SIZE<<2]...
分类:
其他好文 时间:
2014-06-08 15:40:21
阅读次数:
208
Problem Description
Given a list of phone numbers, determine if it is consistent in the sense that no number is the prefix of another. Let’s say the phone catalogue listed these numbers:
1. Emergenc...
分类:
其他好文 时间:
2014-06-08 10:31:22
阅读次数:
234
Problem Description
Ignatius is so lucky that he met a Martian yesterday. But he didn't know the language the Martians use. The Martian gives him a history book of Mars and a dictionary when it leave...
分类:
其他好文 时间:
2014-06-08 03:55:37
阅读次数:
273
题目意思:有n个村庄,编号1-n,以矩阵的形式给出任意两个村庄之间的距离,然后告诉已经有q个村庄已经修好了路,问现在要打算使所有村庄都联通需要修路的最小长度。
思路就是构造一棵最小生成树,所以将距离排序,从小到大依次并入,直到集合数为1为止。...
分类:
其他好文 时间:
2014-06-08 03:22:29
阅读次数:
289
Problem Description
A hat’s word is a word in the dictionary that is the concatenation of exactly two other words in the dictionary.
You are to find all the hat’s words in a dictionary.
In...
分类:
其他好文 时间:
2014-06-08 03:02:14
阅读次数:
323