随笔分类 - 数据结构
摘要:转载自C/C++程序员之家本文原始链接地址:STL中优先队列的使用队列的特点是先进先出。通常都把队列比喻成排队买东西,大家都很守秩序,先排队的人就先买东西。但是优先队列有所不同,它不遵循先进先出的规则,而是根据队列中元素的优先权,优先权最大的先被取出。通常把优先队列比喻成现实生活中的打印。一个打印店里有很多打印机,每台机器的性能不一样,有的打印机打印很快,有的打印机打印速度很慢。当这些打印机陆陆续续打印完自己的任务时进入排队等候状态。如果我这个时候要打印一份文件,我选的不是第一个排队的打印机,而是性能最好,打印最快的打印机。重点:优先级队列,是要看优先级的,谁的优先级更高,谁就先得到权限。不分
阅读全文
摘要:/* 说到底,还是并查集; 当然这题比较特殊;*/一般的并查集应该这么写: for(int i = 1; i #include #include #include #include #include #include #define maxn 2005 int father[maxn],sex[maxn]; using namespace std; int find(int x) //查找根
{ if(father[x]==x) return x; else return father[x] = find(father[x]);
} void Uni...
阅读全文
摘要:/* 学习李大牛每天复习之前写过的算法,每天找一题出来做做复习; *****并查集篇*******/这还算是一道简单的并查集,思路在代码中:15MS340K#include #include #include #include #include #include #include #define x m*(i-1)+j //define 实际上是字符替换,利用这一点将题中本应该是m*(i-1)+j的地方替换为x //使得程序简洁
using namespace std;
char m...
阅读全文
摘要:题目:http://acm.hdu.edu.cn/showproblem.php?pid=1272AC代码:#include #include #include #define maxn 100001
using namespace std; int set[maxn],num[maxn];
int find(int x)
{ if(set[x] == x)return x; return set[x] = find(set[x]);
}
int main()
{ int n,m,pos; while(scanf("%d%d",&n,&m)) { if(m=
阅读全文
摘要:并查集还是挺简单的,路径压缩,按秩合并(这个很麻烦,建议了解就好,主要是路径压缩,我写的代码也只是普通的合并);前天学的,要练练手,以防生疏;http://acm.hdu.edu.cn/showproblem.php?pid=1232#include #include #define maxn 10010
#define INF 999999999
using namespace std; int map[maxn][maxn],set[maxn];
int find(int x)
{ if(set[x] == x)return x; return set[x] = find(set...
阅读全文
摘要:第一次做并查集,MARK。。。这是一道简单的并查集题目,(连我都能做出来,当然简单了),题目大意是,有10000000人排队来,他们当中 两个 两个是朋友,朋友的朋友也是朋友,(把他们归为一个集合);输入是:n,接下来n组数据,每组a,b代表a和b是朋友,输出最大朋友圈的人数;题目:More is betterTime Limit: 5000/1000 MS (Java/Others)Memory Limit: 327680/102400 K (Java/Others)Total Submission(s): 7376Accepted Submission(s): 2708Problem De
阅读全文

浙公网安备 33010602011771号