- 博客(7)
- 收藏
- 关注
原创 最短路
Floydfor (k = 1; k <= n; k++) { for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]); } }}Dijkstravoid dijkstra(int n){ int visit[1001]={0}; int min,i,j,k; visi
2021-01-31 08:20:13 66
原创 线段树
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int N=100010;int a[N],b[N];struct segmentTree { int l,r,sum;} node[N << 2];void pushUp(int i) { node[i].sum = node
2021-01-26 08:11:00 71
原创 bfs和dfs
#define pii pair<int,int>int dx[M]={0,0,1,-1};int dy[M]={1,-1,0,0};int sx,sy;void bfs(){ queue<pii>q; q.push(make_pair(sx,sy)); dis[sx][sy]=0; while(!q.empty()){ int x=q.front().first,y=q.front().second; q.pop(); for(int i=0;i<
2021-01-24 08:13:17 101
原创 二分查找
#include<stdio.h>#include<iostream>#include <algorithm>using namespace std;const int maxN=1e8;int n,m;int a[maxN];bool p(int x){ int f=a[0],sum=1; for(int i=1;i<n;i++){ if(a[i]-f>=x){ f=a[i]; sum++; } if(sum>
2021-01-23 08:31:01 142
原创 并查集的实现
并查集,即把有关系的一部分放到一个集合中。主要函数有两个:int find(int i){ if(f[i]==i) return i; else{ f[i] = find(f[i]); return f[i]; }}这段代码主要实现找到 i 的祖宗以及实现路径压缩,void merge(int i,int j){ int t1,t2; t1 = getf(i); t2 = getf(j); if
2021-01-22 07:36:54 75
原创 Let the Balloon Rise HDU-1004
Let the Balloon RiseContest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges’ favorite time is guessing the most popular problem. When the contest is over, they will count the balloons of each color and f
2021-01-20 22:41:54 81
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人