自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

  • 博客(47)
  • 资源 (2)
  • 收藏
  • 关注

原创 ZOJ 3059 Die Board Game

<br />/*<br /> * File:   ZOJ  3059 Die Board Game<br /> * Author: xiaotian @ hnu<br /> * Created on 2010年11月2日, 上午9:26<br /> * 解题:骰子宽搜索问题,写的猥琐了一点,手动打表量很少。<br /> * 一般情况下骰子的两个相邻的面确定一个状态,再加上位置(x,y)就是三维的状态<br /> * 状态空间为 N*M*24 ,实际上开的是 N*M*36 的数组<br

2010-11-02 17:01:00 611

原创 ZJU 3362 Beer Problem

/* * File: ZJU 3362 Beer Problem * Author: xiaotian @ hnu * Created on 2010年10月30日, 下午12:05 * 解题: */#include#include#include#includeusing namespace std;const int N = 105;const int E = 8100;const int inf = 0x7ffffff;int minc

2010-10-30 12:27:00 330

原创 ZOJ 2314 Reactor Cooling

<br />无源汇上下界可行流<br /><br /><br />这算是上下界网络流问题里最简单的了吧。<br /><br /><br />做法:添加源点 s 和汇点 t 。<br />拆边,对于边(u,v,b,c),添边:(u,v,c-b),(s,v,b),(u,t,b)。<br />求 s 到 t 的最大流,若 maxflow==sigma(bi)  则有解,否则无解。<br /> <br />#include<stdio.h>#include<iostream>#include<string.

2010-10-18 21:06:00 442

原创 PKU 2112 Optimal Milking

<br /> * File:   PKU 2112 Optimal Milking<br /> * Author: xiaotian @ hnu<br /> * Created on 2010年10月16日, 上午9:26<br /> * 题解:最大流+二分验证<br /> * 建图方法:首先从源点到所有 milk machine 连一条边,容量为 M ,<br /> * 再从所有的 cow 连一条边到汇点,容量为 1 。<br /> * 二分一个距离 dis,如果某一个 milk

2010-10-16 10:20:00 339

原创 HDU 1045 Fire Net

<br />二分匹配飘过<br /> <br />好久没有写过二分匹配的题目了,今天写了一个,有点手生,好长时间才建出图来。<br /> <br />建图方法:横竖分区。先看每一列,同一列相连的空地同时看成一个点,显然这样的区域不能够同时放两个点。这些点作为二分图的X部。同理在对所有的行用相同的方法缩点,作为Y部。<br />连边的条件是两个区域有相交部分。最后求最大匹配就是答案。<br /> <br />比如样例一:<br /> 4<br />.X..<br />....<br />XX..<

2010-10-14 21:12:00 811

原创 PKU 2372 Get Luffy Out

<br /> * File:   PKU 2372 Get Luffy Out<br /> * Author: xiaotian @ hnu<br /> * Created on 2010年10月11日, 上午9:52<br /> * 题解:二分 + 2-sat验证<br /> * 建图:对于每一对钥匙(X,Y),如果使用X就不能使用Y,故添加边(X,Y'),(Y,X').<br /> * 对于每一扇名门,只需打开其中一把锁即可,故添加边(X',Y),(Y',X).<br /> <br

2010-10-11 15:59:00 429

原创 2-sat 模板

<br />/* * File: 2-sat 模板 * Author: xiaotian @ hnu * Created on 2010年10月11日, 上午9:52 * 题解:2-sat问题求解 * 建图:将每一个点拆成 p 和 p'(编号时 p'=p+n ) * 如果 ap 和 bp 矛盾,则添加边:(ap,bp'),(bp,ap'). */#include<stdio.h>#include<iostream>#include<string.h>#incl

2010-10-11 13:28:00 1273

原创 PKU 3678 Katu Puzzle

<br /> * File:   PKU 3678 Katu Puzzle<br /> * Author: xiaotian @ hnu<br /> * Created on 2010年10月11日, 上午9:52<br /> * 题解:2-sat问题求解<br /> * 建图:按照如下方法添边<br /> * (1)A and B = 0   A->!B , B->!A<br /> * (2)A and B = 1   !A->A , !B->B<br /> * (3)A or

2010-10-11 13:23:00 434 1

原创 PKU 3207 Ikki's Story IV - Panda's Trick

<br /> * File:   PKU 3207 Ikki's Story IV - Panda's Trick<br /> * Author: xiaotian @ hnu<br /> * Created on 2010年10月11日, 上午9:52<br /> * 题解:经典的2-sat问题,把连线看成点,每条线有两种形式,即圆内(r)、圆外(r')。<br /> * 建图方法:假设两条线(a,b)的同一种形式会相交,那么如果选择 ar,那么必定不能选择 br,只能选择 br'<br

2010-10-11 10:41:00 417

原创 HDU 2485 Destroying the bus stations

<br />网络流 <br /> <br />要求割点的数量,可以转化为求割边的数目,即拆点。<br /> <br />先bfs两次,求出起点和终点到其余各点的距离。然后将每个点拆成两个点,容量为 1 。如果dist1[i]+dist2[j]<k,则给 i' 和 j 连一条边,容量为 1 。<br /> <br />最后求最大流,就是答案。<br /> <br />/* * File: HDU 2485 Destroying the bus stations * Author: xiaotia

2010-10-10 19:13:00 1075

原创 最大流 FF 模板

#define N 205#define inf 0x7fffffint edge[N][N];int chk[N],n;int father[N];int Ford_Fulkerson(){ while(1) { queue q; memset(chk,0,sizeof(chk)); memset(father,-1,sizeof(father)); int now; chk[0]=1; q.push(0);

2010-10-09 12:52:00 405

原创 Dinic 邻接表实现

<br />/* Dinic最大流 O(V^2 * E)INIT: ne=2; head[]置为0; addedge()加入所有弧;CALL: flow(n, s, t); */#define typec int // type of coststruct edge { int x, y, nxt; typec c;} bf[E];int ne, head[N], cur[N], ps[N], dep[N];void addedge(int x, int y,

2010-10-09 12:50:00 458

原创 Dinic 数组实现

<br />int g[N][N]; /*剩余流*/bool vis[N]; /*标记数组*/int level[N];int n, m; /*顶点数,边数*/int src, sink; /*scr源 sink汇*/int build(){ /* 建图 */}int find(int x) { for (int i = 1; i <= n; i++) { if (g[x][i] != 0 && level[i] == level[x] +

2010-10-09 12:17:00 267

原创 UVA 10249 The Grand Dinner

<br />晚宴桌子分配,同一个队伍的人不能坐在同一个桌子旁边。求存不存在这样的分配方案,存在则输出方案。<br /> <br />典型的最大流。<br /> <br />建图方法:从源点连一条边到所有的队伍,流量为队伍成员数量;<br />从所有桌子连一条边到汇点,流量为桌子容量;<br />从每个队伍连一条边到每一个桌子,流量为1,表示这个队伍到这个桌子只能去一个人。<br /> <br />求最大流,若最大流量等于所有人数,则表示可行,否则不可行。<br /> <br />输出方案可以从剩余网络中得到

2010-10-09 12:00:00 497

原创 Timus 1069. The Prufer code

<br /> * File:   Timus 1069. The Prufer code<br /> * Author: xiaotian @ hnu<br /> * Created on 2010年10月9日, 上午9:35<br /> * 题解:思维题目。给定一棵树的编码方式,让还原这棵树。<br /> * 编码方式:每次取编号最小的叶节点和与其相连的边删掉,写下这个叶节点的父亲节点。重复以上操作,直到只有一个节点的时候,这个节点编号必然是 n 。<br /> * 还原方式:可以发现

2010-10-09 10:25:00 351

原创 UVA 10158 并查集

<br />就是并查集的操纵<br />/* * File: UVA 10158 War * Author: xiaotian @ hnu * Created on 2010年10月9日, 上午8:56 * 题解:并查集 */#include<stdio.h>#include<iostream>#include<string.h>#include<queue>#include<map>#include<set>#include<math.h>usin

2010-10-09 09:31:00 626

原创 HNU 11072 && PKU 3635 Full Tank?

优先队列广搜/* * File: PKU 3635 Full Tank? * Author: xiaotian @ hnu * Created on 2010年10月8日, 下午4:27 * 题解:优先队列bfs */#include#include#include#include#include#include#includeusing namespace std;#define N 1008#define inf 0x7fffffffs

2010-10-08 17:06:00 523

原创 PKU 3522 Slim Span

<br />最瘦生成树<br /> <br />即求生成树中最大边和最小边差值最小<br /> <br />/* * File: PKU 3522 Slim Span * Author: xiaotian @ hnu * Created on 2010年10月8日, 上午11:10 * 题解:最瘦生成树 */#include<stdio.h>#include<iostream>#include<string.h>#include<queue>#include<ma

2010-10-08 13:03:00 480

原创 PKU 2377 Bad Cowtractors

<br /> <br />最大生成树<br /> <br />最大生成树/* * File: PKU 2377 Bad Cowtractors * Author: xiaotian @ hnu * Created on 2010年10月8日, 上午11:10 * 题解:最大生成树 */#include<stdio.h>#include<iostream>#include<string.h>#include<queue>#include<map>#includ

2010-10-08 12:25:00 405

原创 最短路计数

<br />#include<stdio.h>#include<iostream>#include<string.h>#include<queue>#include<set>#include<math.h>using namespace std;#define N 1008#define inf 0x7ffffffstruct node { int e, d; node(int a, int b) : e(a), d(b) {} bool o

2010-10-08 10:50:00 383

原创 PKU 3463 Sightseeing

<br />PKU 3463 Sightseeing<br /><br />题解:求最短路以及次短路(比最短路长1)的路的条数,递推求解,四种转移<br /> <br />/* * File: PKU 3463 Sightseeing * Author: xiaotian @ hnu * Created on 2010年10月8日, 上午9:24 * 题解:求最短路以及次短路(比最短路长1)的路的条数,递推求解,四种转移 */#include<stdio.h>#includ

2010-10-08 10:19:00 443

原创 HNU 10862 Ticket to Ride

<br />所谓最小斯泰纳树,很裸,直接套版<br /> <br />/* * File: HNU 10862 Ticket to Ride * Author: xiaotian @ hnu * Created on 2010年10月6日, 下午7:48 * 题解:最小斯泰纳树,直接套板 */#include<stdio.h>#include<iostream>#include<string>#include<queue>#include<map>#incl

2010-10-06 20:49:00 391 1

原创 HNU 10670 && PKU 3177 Redundant Paths

<br />题意是给一个无向图,求添加最少的边使得图中没有桥。<br />(这样理解:例如一个公路网,有时候某些公路损坏需要检修的时候,为了不影响正常的交通,这个公路网中应该存在另外的路径使得要检修的路所连接的两个点依然联通。如果不存在这样的路径,那么所检修的这条路就叫做无向图中的桥。这个命名很生动。)<br />求解:先求出双连通分量,将其缩点。最后会得到一棵树。找出度为1的点,设为 T ,那么至少要添加的边数位:(T+1)/2。<br />怎么证明这个结论?不太懂。这么想吧:首先

2010-10-06 14:02:00 275

原创 强连通分量 tarjan 模板

/*Tarjan强连通分量INIT: g[]为邻接表; stop, cnt, scnt置0; pre[]置-1;CALL: for(i=0; i g[N];int id[N], pre[N], low[N], s[N], stop, cnt, scnt;void tarjan(int v, int n) // vertex: 0 ~ n-1{ int t, minc = low[v] = pre[v] = cnt++; s[stop++] = v; for

2010-10-06 10:59:00 568

原创 强连通分量(POJ 2186 Popular Cows)

<br />/* <br /> * File:   PKU 2186 Popular Cows<br /> * Author: xiaotian @ hnu<br /> * Created on 2010年10月6日, 上午9:50<br /> * 题解:求强连通分量、缩点。<br /> * 检查出度为0的“点”的个数,这里的点指的是每一个强连通分量<br /> * 当出度为 0 “点”的个数仅为 1 时输出该联通分量里的点的个数<br /> * 否则输出 0 。<br />

2010-10-06 10:56:00 284

原创 Timus 1096. Get the right route plate!

<br />/* * File: Timus 1096. Get the right route plate! * Author: xiaotian @ hnu * Created on 2010年10月5日, 下午6:55 * 题解:简单的bfs,可以预先建一个表,bfs起来就很方便 */#include<stdio.h>#include<iostream>#include<string.h>#include<queue>#include<map>#inc

2010-10-05 19:35:00 294

原创 1056. Computer net

1056. Computer net<br />/* * File: Timus * Author: xiaotian @ hnu * Created on 2010年10月5日, 下午3:06 * 题解:twice bfs 第一次找离节点1最远的点K,再找离K最远的点X, * K--X就是最长链,链上的中点就是中心 O(n) */#include <stdio.h>#include <stdlib.h>#include <string.h>#include

2010-10-05 16:14:00 272

原创 Timus 1045. A funny game

<br />/* * File: Timus 1045. A funny game * Author: xiaotian @ hnu * Created on 2010年10月4日, 上午9:51 * 题解: */#include<iostream>#include<stdio.h>#include<queue>using namespace std;#define N 1008struct arr { int win, used;} f[10

2010-10-05 13:14:00 285

原创 闲话最小生成树

<br />最小生成树,什么是最小生成树?<br /><br />比较官方的定义:设G=(V,E)是一个无向连通带权图,即一个网络。E中每条边(u,v)的权为cost。如果G的子图G‘是一棵包含G的所有顶点的树,则称G’为G的生成树。生成树上边权总和为该生成树的耗费。在G的所有生成树中,耗费最小的即为G的最小生成树。<br /><br />简单的说:一个连通图中,用花费最少的边使得该图依然连通。<br /><br />解决最小生成树问题,是一个经典的贪心过程。通常有两种算法<br /><br /

2010-10-05 11:01:00 278

原创 PKU 2449 Remmarguts' Date(第 k 短路模板)

<br /> PKU 2449 Remmarguts' Date<br /> <br />/* * File: PKU 2449 Remmarguts' Date * Author: xiaotian @ hnu * Created on 2010年10月5日, 上午10:25 * 题解:求第 k 短路,dijkstra + A* 搜索 */#include<iostream>#include<stdio.h>#include<string.h>#include<q

2010-10-05 10:42:00 1066 2

原创 Timus 1450. Russian pipelines

/* * File: Timus 1450. Russian pipelines * Author: xiaotian @ hnu * Created on 2010年10月4日, 下午4:06 * 题解:DP求最长路 */#include#include#includeusing namespace std;#define N 505#define INF 0x7ffffffffLLlong long G[N][N], dp[N];bool v[N

2010-10-04 16:13:00 330

原创 Timus 1742. Team building

<br />Timus 1742. Team building<br /> <br />/* * File: Timus 1742. Team building * Author: xiaotian @ hnu * Created on 2010年10月4日, 下午2:54 * 题解: */#include <iostream>#include <string>#include <set>#include <map>#include <vector>#inc

2010-10-04 15:53:00 325

原创 spfa 差分约束

<br />spfa 差分约束<br /> <br />/* spfa 差分约束首先构造约束图,构造不等式时>=表示求最小值, 作为最长路,<=表示求最大值, 作为最短路 (v-u <= c:a[u][v] = c)用addedge加如所有的边返回0表示无解,返回1表示有可行解,可行解存在 dis 数组里 */bool vis[N];int cnt[N],dis[N],head[N];int V[E], next[E];int W[E];int ne, n, m;void

2010-10-04 11:19:00 296

原创 BellmanFord 单源最短路

BellmanFord单源最短路/*BellmanFord单源最短路O(VE)| 能在一般情况下,包括存在负权边的情况下,解决单源最短路径问题| INIT: edge[E][3]为边表| CALL: bellman(src);有负环返回0;dist[i]为src到i的最短距| 可以解决差分约束系统: 需要首先构造约束图,构造不等式时>=表示求最小值, 作为最长路, dist[u] + c) { pre[v] = u; return 1; }

2010-10-04 11:00:00 249

原创 最短路 dijkstra 优先队列优化

<br /> <br />Dijkstra O(E * log E)<br /> <br />/* Dijkstra O(E * log E)INIT: 调用init(nv, ne)读入边并初始化;CALL: dijkstra(n, src); dist[i]为src到i的最短距离 */int cost[E], dist[V];int e, pnt[E], nxt[E], head[V], prev[V], vis[V];struct qnode { int v; i

2010-10-04 10:50:00 742

原创 最短路 dijkstra 数组实现

<br />最短路 dijkstra 数组实现<br />/* Dijkstra数组实现O(N^2)Dijkstra --- 数组实现(在此基础上可直接改为STL的Queue实现) g[][] --- 邻接阵,i 到 j 的初始距离dist[] --- beg到其他点的最近距离path[] --- beg为根展开的树,记录父亲结点 */#define INF 0x7ffffff#define N 1008int path[N], vis[N];int g[N][N], dis

2010-10-04 10:42:00 546 1

原创 最大团模板

<br />最大团模板<br /> <br />void clique(int n, int* u, int mat[][MAXN], int size, int& max, int& bb, int* res, int* rr, int* c) { int i, j, vn, v[MAXN]; if (n) { if (size + c[u[0]] <= max) return; for (i = 0; i < n + size - max && i

2010-10-02 16:51:00 359

原创 Dancing Links 重复覆盖模板

<br />Dancing Links 重复覆盖模板<br /> <br />#include<iostream>#include<cstdio>#include<string.h>#include<vector>#include<math.h>#define inf 0x3fffffffusing namespace std;const int N = 1005;const int M = 4000;int U[M], D[M], R[M], L[M], rs[N];

2010-10-02 16:38:00 894

原创 Dancing Links 精确覆盖模板

Dancing Links 精确覆盖模板#include#include#include#include#include#define inf 0x3fffffffusing namespace std;const int N = 305; /*列数*/const int M = 4000; /*点数*/int map[N][N]; /* 01矩阵表 */int U[M], D[M], R[M], L[M], rs[N];int size[N], head, r

2010-10-02 11:43:00 785

原创 Timus 1040. Airline company

<br />/* <br /> * File:   Timus 1040. Airline company<br /> * Author: xiaotian @ hnu<br /> * Created on 2010年10月2日, 上午9:34<br /> * 题解:一次找极长路(即两边不能再加边),将他们依次编号,然后删掉这些边。直至图中没有边为止。输出解即可。<br /> * 不会出现没有解的情况。<br /> */<br /> <br />#include <iostream>

2010-10-02 10:14:00 455

HOJ部分题目源代码

湖南大学HOJ部分题目的源代码,包括中国余数定理等内容的讲解

2009-09-07

Lucky and Good Months by Gregorian Calendar Kaohsiung 2006代码

Kaohsiung 2006 Lucky and Good Months by Gregorian Calendar(ACM HNU 11562 题 代码) 对于日历的处理,类似于10013的题目

2009-08-24

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除