摘要: #include#include#include#includeusing namespace std;#define INF 100000000vector g[1002];int w[1002][1002],d[1002],vis[1002];struct edge{int u;int v;}e[100000];void spfa(int a,int n){ queue q; memset(vis,0,sizeof(vis));//不在队列中 for(int i=2;id[a]+w[a][b]) { d[b]=d[a]+... 阅读全文
posted @ 2013-07-28 21:36 galaxy77 阅读(183) 评论(0) 推荐(0) 编辑
摘要: #include#include#define INF 100000000using namespace std;int g[102][102],d[102],vis[102];int main(){ int i,j,m,n,a,b,c; while(scanf("%d%d",&n,&m)) { if(n==0&&m==0) break; memset(g,0,sizeof(g)); for(i=0;id[j]) { minn=d[j]; x=j; } ... 阅读全文
posted @ 2013-07-28 21:34 galaxy77 阅读(256) 评论(0) 推荐(0) 编辑
摘要: Problem DescriptionAlice lives in the country where people like to make friends. The friendship is bidirectional and if any two person have no less than k friends in common, they will become friends in several days. Currently, there are totally n people in the country, and m friendship among them. A 阅读全文
posted @ 2013-07-28 15:10 galaxy77 阅读(166) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1595第一次写spfa 一路下来都蛮流畅的 而且1a 哇哈哈 纪念一下 ^ _ ^题意 N个点 M条边 其中有一条未知边无法通过 找出第I条边无法通过时的最短路中的最大者(1n 的最短路(若无法通过的边不在最短路的路径中那 那条边最短路也不会变啦)比较得到最大者 就是答案了代码如下#include#include#include#includeusing namespace std;#define INF 100000000vector g[1002];int w[1002][1002],d[1002],vi 阅读全文
posted @ 2013-07-24 10:35 galaxy77 阅读(221) 评论(0) 推荐(0) 编辑
摘要: pre[i]为在深搜过程中i被遍历到的顺序序号 low[i] 为i及其后代能连到的最早的祖先只要u有一个 子结点v存在low[v]>=pre[u]则u是割点 ( 即: v及其后代连不到比u更早的祖先)。而特殊的 要是low[v]>pre[u] 那么(u,v) 就是桥。因为在算法过程中这条件不止成立一次 所以不能一遇到这给条件就输出 割点或桥贴个模板先: 1 #include 2 #include 3 #include 4 using namespace std; 5 vector g[1002]; 6 int pre[1002],low[1002],iscut[1002],c,vi 阅读全文
posted @ 2013-07-24 09:17 galaxy77 阅读(420) 评论(0) 推荐(0) 编辑
摘要: 题目http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2544floyd 判圈算法 参考 http://blog.csdn.net/l03071344/article/details/8707135前面的solve 求k的最前n位我之前用的函数是不晓得为什么不可以。。int solve(int k,int n){char ss[100];sprintf(ss,"%s",k);ss[n]='\0'; 阅读全文
posted @ 2013-07-05 20:48 galaxy77 阅读(413) 评论(0) 推荐(0) 编辑
摘要: 只在快拍的基础上改了一点点 与快速排序算法不同的是,我们关注的并不是元素的左右两边,而仅仅是某一边#includeusing namespace std;int a[100];int p(int left,int right){ int t,temp=a[left]; while(left=temp) right--; } return left;}int pai(int low,int high,int m){ int u; u=p(low,high); if(u==m) return a[u]; else ... 阅读全文
posted @ 2013-06-27 21:07 galaxy77 阅读(218) 评论(0) 推荐(0) 编辑
摘要: 优先队列使用这个是转得网上的,由于不经常使用,偶尔用的时候还经常出错,所以记下来了,经常使用的已经用红色颜色标出来了 :在优先队列中,优先级高的元素先出队列。标准库默认使用元素类型的<操作符来确定它们之间的优先级关系。优先队列的第一种用法,也是最常用的用法:priority_queue<int>qi;通过<操作符可知在整数中元素大的优先级高。故示例1中输出结果为:9 6 5 3 2第二种方法:在示例1中,如果我们要把元素从小到大输出怎么办呢?这时我们可以传入一个比较函数,使用functional.h函数对象作为比较函数。priority_queue<int,vec 阅读全文
posted @ 2013-06-10 21:58 galaxy77 阅读(184) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=3018题意 ——许多蚂蚁 遍历一个图 每一条边只能走一次 问至少要把这些蚂蚁分为几群 说白了就是 至少几笔可以画出一个特定的 图 出来*********************************************欧拉回路:图G,若存在一条路,经过G中每条边有且仅有一次,称这条路为欧拉路,如果存在一条回路经过G每条边有且仅有一次,称这条回路为欧拉回路。具有欧拉回路的图成为欧拉图。判断欧拉路是否存在的方法有向图:图连通,有一个顶点出度大入度1,有一个顶点入度大出度1,其余都是出度=入度。无向图:图连通 阅读全文
posted @ 2013-06-09 21:48 galaxy77 阅读(216) 评论(0) 推荐(0) 编辑
摘要: 用Java来处理高精度问题,相信对很多ACMer来说都是一件很happy的事,简单易懂。用Java刷了一些题,感觉Java还不错,在处理高精度和进制转换中,调用库函数的来处理。下面是写的一些Java中一些基本的函数的及其……头文件:import java.io.*;import java.util.*;import java.math.*;读入:Scanner cin = Scanner (System.in);while(cin.hasNext())//等价于!=EOFn=cin.nextInt();//读入一个int型的数n=cin.nextBigInteger();//读入一个大整数输出 阅读全文
posted @ 2013-06-08 21:42 galaxy77 阅读(265) 评论(0) 推荐(0) 编辑