摘要:
http://poj.org/problem?id=1459题意:有一个电路网络,每个节点可以产生、传递、消耗若干电量,有点线连接结点,每个电线有最大传输量,求这个网络的最大消费量。思路:从源点到发电站连边,流量为发电量,从用户到汇点连边,流量为消费量,再根据电线连双向边,求最大流即可。 1 #include 2 #include 3 #include 4 const int N=220; 5 const int INF=1q;14 memset(pre,-1,sizeof(pre));15 pre[s] = 0;16 int k;17 q.push(s);18... 阅读全文
posted @ 2013-08-14 17:14
N_ll
阅读(236)
评论(0)
推荐(0)
摘要:
http://poj.org/problem?id=3687看题意看了半天没看懂怎么回事,看完Discuss彻底凌乱了。。后来看了题解才懂,就是逆向建图+拓扑排序,建图时要判重边。 1 #include 2 #include 3 int map[202][202]; 4 int n,in[202],ans[202]; 5 int topo() 6 { 7 int i,j; 8 for (i = n; i >= 1; i --) 9 {10 for (j = n; j >= 1; j --)11 {12 if (!i... 阅读全文
posted @ 2013-08-14 15:53
N_ll
阅读(182)
评论(0)
推荐(0)
摘要:
http://poj.org/problem?id=3083S为起点,E为中点,输出S—>E沿左边走的步数,沿右边走的步数,和最短步数。因为S—>E沿左边走的步数等于E—>S沿右边走的步数,故只需DFS搜索沿右边走的步数,改变起止点即可。然后BFS搜索最少步数。 1 #include 2 #include 3 #include 4 #include 5 6 using namespace std; 7 const int N=55; 8 char map[N][N]; 9 int dir[4][2] = {{0,-1},{-1,0},{0,1},{1,0}};//顺时针方向1 阅读全文
posted @ 2013-08-14 11:26
N_ll
阅读(181)
评论(0)
推荐(0)
摘要:
http://poj.org/problem?id=3278 1 #include 2 #include 3 #include 4 #define MAX 1000002 5 using namespace std; 6 int vis[MAX],step[MAX]; 7 int dir[3][2] = {{1,1},{1,-1},{2,0}}; 8 queue q; 9 int n,m;10 void bfs(int s)11 {12 vis[s] = 1;13 q.push(s);14 while(!q.empty())15 {16 s =... 阅读全文
posted @ 2013-08-14 11:16
N_ll
阅读(223)
评论(0)
推荐(0)

浙公网安备 33010602011771号