- 博客(26)
- 收藏
- 关注
原创 POJ 1182 食物链(并查集) 详解
POJ 1182 食物链 (并查集) 详解参考做法比较经典的并查集的题目,主要是要理解路径压缩的过程。 用0 1 2 分别表示A B C的关系。 0吃1,1吃2,2吃0. 动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。 现有N个动物,以1-N编号。每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种。
2017-01-21 21:35:14 19734
原创 QS Network
Sunny Cup 2003 - Preliminary RoundApril 20th, 12:00 - 17:00Problem E: QS NetworkIn the planet w-503 of galaxy cgb, there is a kind of intelligent creature named QS. QScommunicate with each oth
2017-01-31 17:47:14 358
原创 Constructing Roads
There are N villages, which are numbered from 1 to N, and you should build some roads such that every two villages can connect to each other. We say two village A and B are connected, if and only if th
2017-01-31 15:41:01 194
原创 Building a Space Station
You are a member of the space station engineering team, and are assigned a task in the construction process of the station. You are expected to write a computer program to complete the task. The spac
2017-01-31 14:50:48 281
原创 无向图最小生成树
问题N个点M条边的无向连通图,每条边有一个权值,求该图的最小生成树。Input第1行:2个数N,M中间用空格分隔,N为点的数量,M为边的数量。(2 <= N <= 1000, 1 <= M <= 50000) 第2 - M + 1行:每行3个数S E W,分别表示M条边的2个顶点及权值。(1 <= S, E <= N,1 <= W <= 10000)Output输出最小生成树的所有边的权值之和。题
2017-01-31 11:51:31 1376
原创 kruskal 生成最小树
kruskal 算法在排序上最费时,生成树过程复杂度是线性的,所以最终复杂度为o(|E|log|V|)。 可以对比一下prim算法 传送门》》题目链接#include<stdio.h>#include<string.h>#include<queue>#include<algorithm>#define INF 0x3f3f3f3fusing namespace std;int cos
2017-01-31 10:28:11 857
原创 prim 最小生成树
prim 最小生成树从单一顶点开始,普里姆算法按照以下步骤逐步扩大树中所含顶点的数目,直到遍及连通图的所有顶点。输入:一个加权连通图,其中顶点集合为V,边集合为E;初始化:Vnew = {x},其中x为集合V中的任一节点(起始点),Enew = {};重复下列操作,直到Vnew = V:在集合E中选取权值最小的边(u, v),其中u为集合Vnew中的元素,而v则是V中没有加入Vnew的顶点(
2017-01-30 23:24:56 305
原创 负环图检测
探讨负环图的最短路问题是没有意义的。 由于Bellman-Ford算法while(true)最多执行|V|-1次,如果第|V|次还进行了更新那么就还要继续执行|V|次了,通过这个特新便可o(|V|*|E|)判断负环图了。struct edge{int from,to,cost;};edge es[MAX_E];int d[MAX_V];int V,E;bool check(){
2017-01-29 20:12:11 1332
原创 Heavy Transportation
Heavy Transportation(变形最短路问题)Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is
2017-01-27 15:18:52 310
原创 Frogger
Frogger(最短路的变形)Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on another stone. He plans to visit her, but since the water is dirty and full of
2017-01-27 11:13:27 308
原创 Silver Cow Party
Silver Cow Party (最短路)One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A total of M (1 ≤ M ≤ 100,000) unidi
2017-01-26 21:24:45 329
原创 Til the Cows Come Home
Til the Cows Come Home (最短路问题)Bessie is out in the field and wants to get back to the barn to get as much sleep as possible before Farmer John wakes her for the morning milking. Bessie needs her beauty
2017-01-26 17:56:37 262
转载 Vector
Vector (STL) Vector 是C++标准程序库中的一个类,可视为会自动扩展容量的数组,以循序(Sequential)的方式维护变量集合。vector的特色有支持随机存取,在集合尾端增删元素很快,但是在集合中间增删元素比较费时。vector是C++标准程序库中的众多容器(container)之一。 vector以模板(泛型)方式实现,可以保存任意类型的变量,包括用户自定义的数据
2017-01-25 21:33:56 408
原创 How Many Answers Are Wrong 并查集
题意:提问区间[a,b]的和为sum 是否与之前的信息矛盾。求矛盾提问数量思路让所有有关系的区间上下限的值组成集合。 取根的值为0,那么各元素的值为:区间[根,元素]的和。TT and FF are ... friends. Uh... very very good friends -________-bFF is a bad boy, he is always wooing TT to play the fo
2017-01-24 16:15:38 268
原创 【POJ】1456 Supermarket 并查集
Supermarket Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 12319 Accepted: 5464DescriptionA supermarket has a set Prod of products on sale. It earns a profit px for each pr
2017-01-22 20:51:15 13949 1
原创 【POJ】1703 Find them, Catch them 并查集
Find them, Catch themTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 43420 Accepted: 13356DescriptionThe police office in Tadu City decides to say ends to the chaos, as launch a
2017-01-22 16:57:53 1057
原创 【poj-1182】食物链 并查集
食物链Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 66802 Accepted: 19713Description动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。 现有N个动物,以1-N编号。每个动物都
2017-01-20 20:52:42 9464
原创 Wireless Network 并查集
An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all computers in the n
2017-01-20 20:39:05 324
原创 并查集 模板
在计算机科学中,并查集是一种树型的数据结构,其保持着用于处理一些不相交集合(Disjoint Sets)的合并及查询问题。有一个联合-查找算法(union-find algorithm)定义了两个操作用于此数据结构:Find:确定元素属于哪一个子集。它可以被用来确定两个元素是否属于同一子集。Union:将两个子集合并成同一个集合。因为它支持这两种操作,一个不相交集也常被称为联合
2017-01-20 17:11:48 6267
原创 任务执行顺序 贪心
分析: 本题可以抽象成,从一个整数开始,每次减去a,再加上b (a,b都是正数),要求每次操作都不产生负数。针对本题a[i] = R[i], b[i] = R[i] – O[i],注意O[i] 我们给出标准答案——按照b[i]不增的顺序排序,是最“有利”的。为了定义“有利”,我们这样证明我们的结论:如果对于b[0]>=b[1] >=…>=b[x]
2017-01-20 15:41:34 8106
原创 独木舟问题 贪心
n个人,已知每个人体重,独木舟承重固定,每只独木舟最多坐两个人,可以坐一个人或者两个人。显然要求总重量不超过独木舟承重,假设每个人体重也不超过独木舟承重,问最少需要几只独木舟?分析: 一个显然的策略是按照人的体重排序。极端化贪心策略,最重的人要上船——如果最重的人和最轻的人体重总和不超过船的承重,则他们两个占用一条船。否则(因为假设最重的人的体重也不超过船的承重了),最重的
2017-01-20 13:26:54 1615
原创 活动安排问题之二 贪心
有若干个活动,第i个开始时间和结束时间是[Si,fi),活动之间不能交叠,要把活动都安排完,至少需要几个教室?分析:能否按照之一问题的解法,每个教室安排尽可能多的活动,即按结束时间排序,再贪心选择不冲突的活动,安排一个教室之后,剩余的活动再分配一个教室,继续贪心选择……反例: A:[1,2) B:[1,4) C:[5,6) D:[3,7)已经按结束时间排好顺序,我
2017-01-20 13:23:48 9539
原创 活动安排问题 贪心
有若干个活动,第i个开始时间和结束时间是[Si,fi),只有一个教室,活动之间不能交叠,求最多安排多少个活动?分析: 我们就是想提高教室地利用率,尽可能多地安排活动。考虑容易想到的几种贪心策略:(1) 开始最早的活动优先,目标是想尽早结束活动,让出教室。然而, 这个显然不行,因为最早的活动可能很长,影响我们进行后面的活动。例如活动开始和结束时间分别为[0, 100), [1
2017-01-20 13:20:50 7941
原创 完美字符串 贪心
约翰认为字符串的完美度等于它里面所有字母的完美度之和。每个字母的完美度可以由你来分配,不同字母的完美度不同,分别对应一个1-26之间的整数。约翰不在乎字母大小写。(也就是说字母F和f)的完美度相同。给定一个字符串,输出它的最大可能的完美度。例如:dad,你可以将26分配给d,25分配给a,这样整个字符串完美度为77。分析: 由排序不等式,出现次数最多的字母显然应该给26。所以这
2017-01-20 13:17:41 913
原创 Replace To Make Regular Bracket Sequence 括号配对
好久没写文章了|chutzpah.xyz You are given string s consists of opening and closing brackets of four kinds , {}, [], (). There are two types of brackets: opening and closing. You can replace any b
2017-01-19 18:54:49 649
原创 linux常用命令
Redhat系列的Centos 为例这些都是在兄弟连linux视频中学到的,推荐新手看这个视频ls [option] [directory-list] 列出文件夹文件 -a(all)-l(long)-n-i(id)mkdir[option] [directory-list] (make directiories) 创建文件夹 -p (递归创建)cd [directory-list]
2017-01-17 21:35:11 7196
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人