上一页 1 2 3 4 5 6 ··· 8 下一页
摘要: 并查集+set容器 Kruskal#include <stdio.h>#include <string.h>#include <set>using namespace std;const int MAXN = 501;struct E{ int x,y; int weight;};E edge[25001];int father[MAXN];int cmp(const void *d1,const void *d2){ return (*(E*)d1).weight - (*(E*)d2).weight;}void makeSet(int n){ for(i 阅读全文
posted @ 2011-04-21 14:20 L.. 阅读(277) 评论(0) 推荐(0) 编辑
摘要: 基础 Kruskal#include <iostream>#include <stdio.h>using namespace std;const int MAXN = 101;struct E{ int x,y; int weight;};E edge[MAXN*MAXN/2];int G[MAXN][MAXN];int father[MAXN];int cmp(const void *d1, const void *d2){ return (*(E*)d1).weight - (*(E*)d2).weight;}void makeSet(int n){ for(int 阅读全文
posted @ 2011-04-21 14:16 L.. 阅读(317) 评论(0) 推荐(0) 编辑
摘要: 读入边权要注意是否比原来的边权小#include <iostream>#include <fstream>#include <string.h>using namespace std;const int MAXN = 1000;int G[MAXN][MAXN];int lowcost[MAXN];int cloest[MAXN];bool used[MAXN];int cost;void PRIM(int n){ int cnt = 0; cost = 0; used[1] = true; for(int i = 2; i <= n; i++){ l 阅读全文
posted @ 2011-04-21 14:11 L.. 阅读(204) 评论(0) 推荐(0) 编辑
摘要: 最小生成树..#include <iostream>#include <string.h>#include <math.h>#include <iomanip>using namespace std;const int MAXN = 101;struct point { double x,y;};point p[MAXN];double G[MAXN][MAXN];double lowcost[MAXN];int closest[MAXN];bool used[MAXN];double cost;void PRIM(int n){ cost = 阅读全文
posted @ 2011-04-21 13:41 L.. 阅读(146) 评论(0) 推荐(0) 编辑
摘要: 基础的最小生成树 有的路已经建好了,就把矩阵置0 就可以了//prim MST#include <stdio.h>#include <stdlib.h>#include <string.h>int G[101][101]; bool used[101]; int lowcost[101];int closest[101];int cost;void prim(int n){ cost = 0; used[1] = true; int minj; for(int i = 2; i <= n; i++){ lowcost[i] = G[i][1]; clo 阅读全文
posted @ 2011-04-21 13:39 L.. 阅读(152) 评论(0) 推荐(0) 编辑
摘要: 并查集 找连通分量 水之#include <stdio.h>int set[1001];int find(int x){ while(set[x] != x) x = set[x]; return x;}void merge(int x,int y){ int fx , fy; fx = find(x); fy = find(y); if(fx != fy){ set[fx] = fy; }}int main(){ int m,n,i,cnt,x,y; while(scanf("%d",&n),n){ for(i = 1; i <= 1000; + 阅读全文
posted @ 2011-04-21 13:15 L.. 阅读(110) 评论(0) 推荐(0) 编辑
摘要: #include <stdio.h>#define MAXN 21int map[MAXN][MAXN];int startx, starty;int w, h, ok, minMove;int dr[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};int legal(int x, int y){ if(x >= 1 && y >= 1 && x <= h && y <= w ) return 1; return 0;}void in(){ int i, j; for(i = 1; i 阅读全文
posted @ 2011-04-20 23:08 L.. 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 要求求出一串数列中不重合的两段子序列的和的最大值思路:正着求一遍最大子串和,记录在lmax数组中,再倒着求一遍最大子串和,记录在rmax中,这时求出的是包含a[i]的最大和lmax[i],rmax[i],还要将lmax,rmax更新成其区间内的最大和,并不一定包括i,最后求出lmax[i] + rmax[i + 1]的最大值#include <stdio.h>int lmax[50000],rmax[50000],max;int main(){ int cas,n,a[50000],i,j; scanf("%d",&cas); while( cas-- 阅读全文
posted @ 2011-04-20 22:50 L.. 阅读(158) 评论(0) 推荐(0) 编辑
摘要: 做出来要不要这么有感觉啊...以下转自http://hi.baidu.com/%8E%E1%D0%B3/blog/item/2f1d8f4c176a8dc4d1c86af9.html不过他写错了一个改过来了由于深度一定(m),所以使用深度优先搜索,自上而下的设定蛋糕序号,最顶层的为第1层,……,最底层的蛋糕为第m层,很明显满足题目条件的前i层的(从顶层(也就是编号为1的层)开始计数)最小面积mins[i]和体积minv[i]是在该层的半径以及高度都为i时取得,如果采用一般的神搜肯定会超时,所以这题还需要剪枝,剪枝条件有(从m层向上搜,假设前dep层的体积为sumv,面积为sums,当前所得的最 阅读全文
posted @ 2011-04-20 21:19 L.. 阅读(488) 评论(0) 推荐(0) 编辑
摘要: 明显的贪心#include <stdio.h>#include <iostream>#include <vector>#include <algorithm>using namespace std;struct BaoBei{ int p, m; double val;};bool cmp(const BaoBei &a, const BaoBei &b){ return a.p > b.p; // >号 降序排序}int main(){ int v, n; vector<BaoBei> vec; whil 阅读全文
posted @ 2011-04-20 17:46 L.. 阅读(388) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 ··· 8 下一页