摘要: 高斯消元,以前从来没写过,今天的模拟比赛里面,添琦给了我一个模板!虽然是个裸的,但是因为从来没写过,一个小细节竟然搞了我几个小时;终于最后在小珺同志的帮助下成功a掉了,太开心了!存一下,作为模板!代码: 1 #include 2 #define maxn 10 3 #include 4 #include 5 #include 6 #define eps 0.00001 7 using namespace std; 8 double matrix[maxn][maxn+1]; 9 double ans[maxn];10 double a[maxn];11 12 void exchange_col 阅读全文
posted @ 2013-09-08 00:44 Yours1103 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 题目很简单,我却WA了几十次,找错误找了我一个小时;蛋都碎了!后来发现错误的地方竟然是memset;用一个循环来替代它就A了;╮(╯▽╰)╭今晚回去好好的看看memset!!!发个代码纪念下,已经被我改的面目全非; 1 #include 2 #include 3 #define maxn 105 4 using namespace std; 5 double map[maxn][maxn]; 6 int x[maxn],y[maxn]; 7 bool v[maxn]; 8 9 double prim(int n)10 {11 int i,j,flag;12 v[1]=1;13... 阅读全文
posted @ 2013-09-06 17:51 Yours1103 阅读(215) 评论(0) 推荐(0) 编辑
摘要: 也是一道2-sat的入门题;不过题目描述的不清楚,看了别人的题解才知道题意;和上面的那题差不多,一个模板;代码: 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define maxn 20010 7 using namespace std; 8 9 vectorve[maxn];10 stacks;11 int low[maxn],dfn[maxn],b[maxn],nncount,cnt;12 bool instack[maxn];13 14 void tarjin(int u)15 {16 low[u]=dfn... 阅读全文
posted @ 2013-09-05 16:38 Yours1103 阅读(232) 评论(0) 推荐(0) 编辑
摘要: 2-SAT的入门题;网上说这个算法最好的入门教材是:伍昱的《由对称性解2-SAT问题》的ppt和赵爽的论文《2-SAT 解法浅析》;看了一下伍昱的ppt,很好理解!而这道题相对ppt里面的例子来说更加简单;代码: 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define maxn 2010 7 using namespace std; 8 9 vectorve[maxn];10 stacks;11 int low[maxn],dfn[maxn],b[maxn],nncount,cnt;12 bool instack[ma. 阅读全文
posted @ 2013-09-05 15:37 Yours1103 阅读(187) 评论(0) 推荐(0) 编辑
摘要: 这是一道用tarjin求双连通分量的题;其中,不需要修的道路就是桥的数目;在图的每个极大环中,如果点的数目小于边的数目,显然这个环中含有子环,并且这个环的边数就是这个环中有冲突的边的数目;如果点的数模等于边的数目,那就没有冲突;代码: 1 #include 2 #include 3 #include 4 using namespace std; 5 #define maxn 10005 6 7 vectorg[maxn]; 8 int block[maxn],top,stack[maxn],dfn[maxn],low[maxn],index,res1,res2; 9 bool instack. 阅读全文
posted @ 2013-09-05 13:56 Yours1103 阅读(177) 评论(0) 推荐(0) 编辑
摘要: 这是一道双联通分量的题,要用到LCA算法;听说这个算法有两种实现方式:一个是dfs+线段树或着RMQ;一个是用tarjin;我用的是tarjin;题目比较简单,就是每次加了一条边之后剩下的桥的个数;代码: 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 #define MAXN 100009 7 #pragma comment(linker,"/STACk:10240000,10240000") 8 9 int n,m,cnt,NE,BridgeNum; 10 int parent[M 阅读全文
posted @ 2013-09-05 11:04 Yours1103 阅读(202) 评论(0) 推荐(0) 编辑
摘要: 强连通分量——tarjin 算法这道题和前面那道hdu 2767唯一不同就是,2767需要找出最小数量的边使图成为连通分量,而这个题需要一点点贪心的思想在里面,它需要求出代价最小的边使图成为连通分量;代码: 1 #include 2 #include 3 #include 4 #include 5 #define N 50006 6 using namespace std; 7 8 struct Edge 9 {10 int u, val, next;11 Edge() {}12 Edge(int a, int b, int c)13 {14 ... 阅读全文
posted @ 2013-09-04 20:12 Yours1103 阅读(361) 评论(0) 推荐(0) 编辑
摘要: 强连通分量——tarjin算法;这题的思路就是找出多少个出度为0的连通分量,结果就是这些连通分量的元素的最小值相加;一道很简单的题,改了我好久,= =!~贴代码: 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define maxn 1005 7 using namespace std; 8 9 int dfn[maxn],low[maxn],pen[maxn],b[maxn];10 int nncount,ans,cc[maxn],cnt,in[maxn];11 bool instack[maxn];12 vectorv. 阅读全文
posted @ 2013-09-04 20:08 Yours1103 阅读(147) 评论(0) 推荐(0) 编辑
摘要: 这也是道强连通分量的题;题目要求我们求出最少需要添加多少条边让整个图变成一个强连通分量;思路很简单,直接缩点,然后找出所有点中有多少出度为0,入度为0的点,最大的那个就是题目所求;贴代码: 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define maxn 50005 7 using namespace std; 8 vectorve[maxn]; 9 int dfn[maxn],low[maxn],ans,n,m,nncount,b[maxn];10 int from[maxn],to[maxn],cntin[maxn] 阅读全文
posted @ 2013-09-04 20:02 Yours1103 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 强连通分量题,用tarjin算法;这是一道很简单的tarjin算法题,基本上就是套模板;贴代码:#include#include#include#include#define maxn 10005using namespace std;vectorve[maxn];int dfn[maxn],low[maxn],ans,n,m,nncount;bool instack[maxn],vis[maxn];stackq;void tarjin(int x){ dfn[x]=low[x]=++nncount; vis[x]=1,instack[x]=1; q.push(x); ... 阅读全文
posted @ 2013-09-04 19:57 Yours1103 阅读(237) 评论(0) 推荐(0) 编辑