神奇的DP:用2个数组r[i],l[i]表示以第i个矩形的高度并包含这个矩形所组成的最大矩形的左右宽度的边界位置;扩展左边界:1。如果第j个矩型的高度比第i个矩阵(1<j<i)的高度低则做边界位置为i,即l[i]=j+1,终止;2。如果高(或相等),则继续向左扩展,直到符合条件1。就终止。扩展右边界:类扩展左边界。以下对于扩展左边界的解释:n(100000)数据很大,如果用以下方法做(类似暴力吧),我们模拟一下发现,如果第j个矩阵扩展的左边界已经得到,在扩展其他第i(i>j)个矩阵时做了很多第j个矩阵扩展的操作,重复了,这样做 无疑 地TLE了;错误做法:for(i=1;i& Read More
posted @ 2012-08-05 09:24 To be an ACMan Views(531) Comments(0) Diggs(0)
本题关键是建图,然后SAP水一个建图:设0为源点,1为汇点,所以检索表里的插头下标要从2开始。先输入n个插座,每个插座与汇点相连,值为1。再输入m个用电器,用电器的名称其实是个无用的信息,把每个用电器的插头与源点相连,值为1。然后输入k个转换器,如B X,则B与X连,注意值为INF(无穷大),因为这种类型的转换器可以有无数个。最后SAP水一个,水题鉴定完毕。View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define INF 100000 Read More
posted @ 2012-08-04 23:12 To be an ACMan Views(237) Comments(0) Diggs(0)
sap模板题,输入比较麻烦,漏了个分号检查了半天View Code #include<stdio.h>#include<string.h>#include<algorithm>#define maxn 105#define INF 100000000using namespace std;int c[maxn][maxn],dis[maxn],num[maxn];int pre[maxn];int s, t, vs;int n, m, np,nc;void sap(){ memset(dis,0,sizeof(dis)); memset(num,0,size Read More
posted @ 2012-08-02 23:14 To be an ACMan Views(211) Comments(0) Diggs(0)
dinic1719MSView Code #include<stdio.h>#include<string.h>#include<algorithm>#include<queue>using namespace std;#define INF 1000000#define maxn 250int dis[maxn][maxn];int c[maxn][maxn];bool vis[maxn];bool sign[maxn][maxn];int K,C,M;int s, t, n;void floyd(){ int i, j, k; for(k=1 Read More
posted @ 2012-08-02 21:10 To be an ACMan Views(203) Comments(0) Diggs(0)
sap+gap优化View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define maxn 105#define inf 1000000000int min(int a, int b){ return a < b ? a : b;}struct E{ int v, next, c;}edge[10003 << 1];int head[maxn], tot;int n, m;void add(int s, int t, in Read More
posted @ 2012-07-29 17:49 To be an ACMan Views(229) Comments(0) Diggs(0)
最近比较懒,一种方法A了以后不想再去学习别的方法,诶,需要调整本题:邻接表 + bfs +优先队列 32MS还行View Code #include<stdio.h>#include<string.h>#include<queue>using namespace std;#define INF 100000000#define maxn 103#define maxm 10003struct node{ int c, l, w; node(int cc,int ll,int ww):c(cc),l(ll),w(ww) {} friend bool opera Read More
posted @ 2012-07-28 15:22 To be an ACMan Views(227) Comments(0) Diggs(0)
把每种颜色看做是图的顶点,然后判定是否满足欧拉回路的条件,用并查集来判断图的各个点是否连通(即是否只用一颗树),用字典树记录颜色编号。1.字典树:本题数据比较大,有50W种颜色,如果用STL的map来记录颜色或人工处理的话都会超时(平均O(n/2));所以我们用字典树来记录颜色的编号(平均O(lgn)),大大节约了时间。2.欧拉回路判定:本题显然是单向图,用d[]数组来统计每种颜色的度,满足欧拉回路的条件:顶点的度为奇数的个数只能是2或0,其它点的度必须都为偶数;3.并查集:用并查集来判断图的各个点是否连通(即是否只用一颗树);View Code #include<stdio.h> Read More
posted @ 2012-07-28 11:25 To be an ACMan Views(220) Comments(0) Diggs(0)
POJ 1300 ZOJ 1395 Door Man 欧拉回路的判定输入比较麻烦,其它感觉就是好水哦View Code #include<stdio.h>#include<string.h>int main(){ int i,j; char buf[128]; int n,m; int door[22]; while(gets(buf)!=NULL) { if(!strcmp(buf,"ENDOFINPUT"))break; if(buf[0]=='S') { sscanf(buf,"%*s %... Read More
posted @ 2012-07-27 13:47 To be an ACMan Views(247) Comments(0) Diggs(0)
我靠,这么水的题目让我那么纠结,直到A了也不知道数据范围为多大。View Code #include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>#include<queue>#define maxn 50005using namespace std;int cost[maxn],head[maxn];bool vis[maxn];long long dis[maxn];struct node{ int v,w,next;}list[maxn*2];in Read More
posted @ 2012-07-24 21:33 To be an ACMan Views(190) Comments(0) Diggs(0)
字符串处理+dijkstra修改一下View Code #include<stdio.h>#include<string.h>#define maxn 201int n,m,num;int dis[maxn],adj[maxn][maxn];bool vis[maxn];int MIN(int a ,int b){ return a < b ? a : b;}int MAX(int a, int b){ return a > b ? a :b;}char str[201][35],s[35];int find(){ int i; for(i=0;i<n Read More
posted @ 2012-07-24 18:52 To be an ACMan Views(203) Comments(0) Diggs(0)