上一页 1 ··· 5 6 7 8 9 10 11 12 13 下一页
摘要: 题意:给出一张n个点m条边的无向图,然后又q组查询,询问从s节点走到m节点至少要经过多少条桥思路:先dfs找桥,并给所有边-双连通分量蓝色。根据找到的桥以及桥的两端的节点的颜色,重新建图(每个节点代表一个双连通分量,其实就是形成一棵树),dfs一遍求各个点的深度,然后就是离线的求LCA,距离就是dis[u]+dis[v]-2*dis[LCA(u,v)] 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define maxn 100010 7 using namespace std; 8 9 int... 阅读全文
posted @ 2013-08-06 08:53 浙西贫农 阅读(297) 评论(0) 推荐(0) 编辑
摘要: 看了chenxing老湿的代码,我真心为自己智商捉鸡啊。。一遍dfs搞定啊。。 1 #include 2 #include 3 #define maxn 110 4 int first[maxn],v[maxn*2],next[maxn*2]; 5 int len,e; 6 inline int max(int a,int b){ 7 return a > b ? a : b; 8 } 9 10 void init(){11 e = 0;12 memset(first,-1,sizeof(first));13 }14 15 void add_edge(int a,i... 阅读全文
posted @ 2013-08-05 18:06 浙西贫农 阅读(239) 评论(0) 推荐(0) 编辑
摘要: 我也搞不懂为什么我每次做这种明明很简单清晰的题目总是会想出那么操蛋的办法,诶。贴个正常的: 1 #include 2 typedef long long LL; 3 LL a[20]; 4 LL count(LL num){ 5 int bit[20],cnt = 0; 6 LL tmp = num; 7 while(tmp > 0){ 8 bit[cnt++] = tmp % 10; 9 tmp /= 10;10 }11 if(cnt == 1) return num - 1;12 LL ans = 9;... 阅读全文
posted @ 2013-08-05 15:02 浙西贫农 阅读(252) 评论(0) 推荐(0) 编辑
摘要: 最近发现,不写题解不长记性。题意:给出一张带权无向图,然后询问该图的每条边进行询问,若这条边出现在该图的所有最小生成树中,输出any;若这条边可以出现在这张图的某几个最小生成树中,输出at least once;若这条边不会出现在这张图的任意一个最小生成树中,输出none。解法:跟求最小生成树的方法类似,首先将所有边按照权值从小到大排序,一次取出所有边长相等的边,查询每条边的两个节点是否在同一集合中,若不在同一集合中,则在这两个集合间添加一条无向边,同时认为这些边有可能出现在该图的最小生成树中。再做tarjan找桥,找到桥将一定出现在该图的最小生成树中。然后将所有的边的两个端点合并到同一集合, 阅读全文
posted @ 2013-08-02 15:41 浙西贫农 阅读(575) 评论(0) 推荐(0) 编辑
摘要: 这是白书二代上的一个组合计数里面的一道练习题。我用的方法是枚举在x*y的方格中放置一条对角线,也可以理解为枚举斜率。如图,先来看这样一个问题,n=m=4,即此时有3行3列的方格的时候,可以放置斜率k=-1的直线有多少条。首先我们把每个格子都标上号。如图,我最多只能放置5条k=-1的直线。当我枚举在1*1的方格中放置对角线的时候(当然此时斜率k=-1),一共可以放置9条对角线。然而事实上斜率k=-1的对角线只需要5条就可以了,多出来了4条。那么是哪里多出来了这4条呢?我们注意看所有2*2的方格,他们多有的右下角的那条都是多余的。如图:很显然,我们需要删掉1245中的5,2356中的6,4578中 阅读全文
posted @ 2013-05-07 15:43 浙西贫农 阅读(777) 评论(0) 推荐(0) 编辑
摘要: 用spfa做的时候 标记每个点的被松弛的次数 即可。View Code 1 #include <iostream> 2 #include <vector> 3 #include <cstring> 4 #include <queue> 5 #include <string> 6 #include <map> 7 #include <cstdio> 8 #define maxn 110 9 #define INF 1 << 30 10 using namespace std; 11 typedef p 阅读全文
posted @ 2013-03-03 12:30 浙西贫农 阅读(377) 评论(0) 推荐(0) 编辑
摘要: d[i]=区间[0,i)中所有的整点数。得到两个不等式:d[b+1]-d[a]<=c,0<=d[i+1]-d[i]<=1;根据这两个不等式来做差分约束。View Code 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <queue> 5 #define maxn 50010 6 #define maxm 150010 7 using namespace std; 8 9 int first[maxn],d[maxn],inq[m 阅读全文
posted @ 2013-01-02 17:06 浙西贫农 阅读(127) 评论(0) 推荐(0) 编辑
摘要: 写的好搓啊。。新年第一水。View Code 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <queue> 5 #define maxn 510 6 #define maxm 2710 7 using namespace std; 8 int v[maxm],w[maxm],next[maxm]; 9 int first[maxn],inq[maxn],cnt[maxn],d[maxn]; 10 int e,V,E; 11 12 void ini 阅读全文
posted @ 2013-01-01 20:34 浙西贫农 阅读(153) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <queue> 5 #include <vector> 6 #define maxn 60 7 using namespace std; 8 vector<int> v,next; 9 vector<double> w; 10 double d[maxn]; 11 int first[maxn],inq[maxn],cnt[maxn]; 12 i 阅读全文
posted @ 2012-12-15 17:42 浙西贫农 阅读(191) 评论(0) 推荐(0) 编辑
摘要: 虽然这个题写的很挫。但还是水一下。View Code 1 #include <iostream> 2 #include <vector> 3 #include <queue> 4 #include <cstring> 5 #include <cstdio> 6 #define INF 1 << 20 7 using namespace std; 8 typedef pair<int,int> pii; 9 int N,S,E,M,K; 10 int G[505][505],f[505],g[505],T[101 阅读全文
posted @ 2012-12-14 18:56 浙西贫农 阅读(252) 评论(0) 推荐(0) 编辑
上一页 1 ··· 5 6 7 8 9 10 11 12 13 下一页