practice
Servon李泽文
这个作者很懒,什么都没留下…
展开
-
Bellman-Ford 单源最短路径
#include <iostream>using namespace std;int u[100], v[100], w[100];const int INF = 0x3f3f3f3f;int dis[100];int main(){ int n, m; cin>>n>>m; for(int i=1; i<=m; i...原创 2018-03-03 18:23:04 · 224 阅读 · 0 评论 -
放苹果
放苹果题目描述把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法? 5,1,1和1,5,1是同一种分法。输入第一行是测试数据的数目t(0<= t <=20)。以下每行均包含二个整数M和N,以空格分开。 1<=M,N<=10。输出对输出的每组数据M和N,用一行输出相应的K。样例输入17 3样例输出8来源MOOC PKU GuoWei 代码#include <ios原创 2018-03-13 20:47:47 · 253 阅读 · 0 评论 -
逆波兰表达式
//by PKU GuoWei#include <iostream>#include <cstdlib>using namespace std;double exp(){ char s[20]; cin>>s; switch(s[0]){ case '+': return exp()+exp(); ...转载 2018-03-13 20:29:23 · 130 阅读 · 0 评论 -
n皇后问题
#include <iostream>#include <cmath>using namespace std;int queen[100];int n;void printQ(){ for(int i=1; i<=n; i++){ cout<<queen[i]<<' '; } cout<...原创 2018-03-13 20:21:33 · 183 阅读 · 0 评论 -
Kruskal Prim 最小生成树
/*Kruskal, 使用并查集判断两棵树是否连通,还可以用dfs*/#include <iostream>using namespace std;struct edge{ int u, v; int w;};struct edge a[100];int f[100];int n, m;struct edge tmp;void quickSo...原创 2018-03-05 22:05:04 · 177 阅读 · 0 评论 -
并查集
#include <iostream>using namespace std;int f[100];int getf(int v){ if(f[v] == v){ return v; }else { f[v] = getf(f[v]); return f[v]; }}void merge(int u...原创 2018-03-04 23:16:38 · 169 阅读 · 0 评论 -
最小堆
#include <iostream>using namespace std;int h[100];int n;void siftdown(int i){ int t, flag = 0; while(i*2 <= n && flag == 0){ if(h[i] > h[i*2]){ t ...原创 2018-03-04 23:15:59 · 178 阅读 · 0 评论 -
Bellman-Ford 队列优化
#include <iostream>using namespace std;int n, m;int a[100][100], book[100], dis[100];const int INF = 0x3f3f3f3f;int main(){ int que[100]; int head, tail; cin>>n>>...原创 2018-03-04 23:14:50 · 214 阅读 · 0 评论 -
Bellman-Ford 扩展
#include <iostream>using namespace std;int n, m;int u[100], v[100], w[100], dis[100];const int INF = 0x3f3f3f3f;int check = 0, flag = 0;int main(){ cin>>n>>m; for(in...原创 2018-03-04 23:13:39 · 161 阅读 · 0 评论 -
Dijkstra 单源最短路径
Dijkstra单源最短路径#include <iostream>using namespace std;int a[100][100], book[100];int dis[100];const int INF = 0x3f3f3f3f;int main(){ int n, m;//n个顶点,m条边 cin>>n>>m; ...原创 2018-03-03 18:20:54 · 141 阅读 · 0 评论 -
Floyd 多源最短路径
Floyd多源最短路径#include <iostream> using namespace std;int main(){ int a[100][100]; int n, m;//n个顶点,m条边 const int INF = 0x3f3f3f3f; cin>>n>>m; for(int i=1; i&l...原创 2018-03-03 18:18:51 · 239 阅读 · 0 评论 -
输出前k大的数
题目描述给定一个数组包含n个元素,统计前k大的数并且把这k个数从大到小输出。输入第一行是一个正整数n,表示数组的大小。n < 100000。 第二行包含n个整数,表示数组的元素,整数之间以一个空格分开。每个整数的绝对值不超过100000000。 第三行包含一个整数k。k < n。输出从大到小输出前k大的数。样例输入101 3 5 7 9 2 4 6 8 105样例输出10 9 8 7 6思路原创 2018-03-13 22:34:23 · 944 阅读 · 0 评论