10 2012 档案
摘要:http://www.cppblog.com/LeoW/archive/2012/03/08/167427.htmlView Code #include<stdio.h>#include<string.h>#include<math.h>#define lld __int64int main(){ int i, j, cas; int n; scanf("%d", &cas); while(cas--) { scanf("%d", &n); double sum1 = n*log10(n*1.0); l
阅读全文
摘要:http://www.cnblogs.com/183zyz/archive/2011/04/12/2013372.htmlView Code #include<stdio.h>#include<string.h>int f(int x){ int i, sum = 1; for(i = 1; i <= x; i++) sum *= 10; return sum;}int gcd(int a, int b){ return b ? gcd(b, a%b) : a;}int main(){ int i, j, cas; char s[33]; ...
阅读全文
摘要:思路:枚举每张牌,然后加入这张牌,看这牌是否能胡。判胡:1.注意特判 7 对子,九一 这两个胡牌规则 2.(胡的牌里必须有一个对子)枚举这个对子,然后再进行处理就方便多了注意:情况1特判和情况2的牌可能会重复,要去重。View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int vis[6][11], num[6][11];char a[15][5];struct node{ int x, y; node(){} node(int xx, int
阅读全文
摘要:用拆点把点权变为边权。然后用最大流求解每对u、v(u != v),取其中的最小值注意:具体操作时,有个技巧,可以将枚举从O(n^2)优化到O(n):先固定一个点,然后枚举另一个点即可。很显然的一个结论:max_flow(1->2->3) < max_flow(2->3)我们要取其中的最小,可以不必去求2->3的最大流如果以1为源点,汇点只能是剩下的几个点,枚举汇点即可。本题要多次求最大流,所以每求一次要重新还原原图代码1:先把原图的信息保存在map数组里,每次都重新建图。View Code #include<stdio.h>#include<st
阅读全文
摘要:提两点:1.对于每个点连通分量,都是根据割点来找的。2.边入栈, 到当前边等于栈顶时停止出栈。3.割点属于多个点连通分量。邻接矩阵:View Code #include<stdio.h>#include<string.h>#define maxn 22#define maxm 444#define inf 1000000000int min(int a, int b){ return a < b ? a : b;} int n, m;bool map[maxn][maxn];struct EE{ int u, v; void print() { print...
阅读全文
摘要:注意:对于生成树的每条边<u,v>:u是割点的充要条件是:1、若u为根节点, 它有2个以上包括两个的儿子(son >= 2)2、u不为根节点,dfn[u] <= low[v];View Code #include<stdio.h>#include<string.h>#define maxn 1005#define maxm maxn*maxnint min(int a, int b) { return a < b ? a : b;}int max(int a, int b) { return a > b ? a : b;}struct
阅读全文
摘要:题意:给出n栋房子位置和每栋房子里面的人数,m个避难所位置和每个避难所可容纳人数。然后给出一个方案,判断该方案是否最优,如果不是求出一个更优的方案。思路:很容易想到用最小费用流求出最优时间,在与原方案花费时间对比判断原方案是否最优。但是这种方法会超时的。 放弃该思路。看看题目没要求要最优解,而是得到一个更优的解,那么如果在原图中能够找到一个总费用为负的回路的话,那就该解不是最优解,把该负环消去,更新流量,得到优化后的解。具体操作:在SPFA中,一个点入队次数大于顶点数时就可以判断有负圈存在了,但这时刚刚入队的这个点却未必是负圈上的,如数据1 30 0 41 0 61 1 61 2 60 2 2
阅读全文
摘要:View Code #include<stdio.h>#include<string.h>#include<algorithm>#include<queue>using namespace std;#define maxn 110#define maxm 6000#define inf 1000000000int min(int a, int b){ return a < b ? a : b;}struct E{ int u, v, next, c, w;}edge[maxm<<2];int head[maxn], tot;in
阅读全文
摘要:View Code #include<stdio.h>#include<string.h>#include<algorithm>#include<queue>using namespace std;#define maxn 100300#define maxm 200003#define inf 1000000000int min(int a, int b){ return a < b ? a : b;}struct E{ int u, v, c, w, next;}edge[maxm<<3];int head[maxn], t
阅读全文
摘要:View Code #include<stdio.h>#include<string.h>#include<algorithm>#include<queue>using namespace std;#define maxn 5010#define maxm 10030#define inf 1000000000int min(int a, int b){ return a < b ? a : b;}struct E{ int u, v, c, w, next;}edge[maxm<<3];int head[maxn], tot;
阅读全文
摘要:View Code #include<stdio.h>#include<string.h>#include<algorithm>#include<queue>using namespace std;#define maxn 1010#define maxm 10003#define inf 1000000000int min(int a, int b){ return a < b ? a : b;}struct E{ int u, v, c, w, next;}edge[maxm<<3];int head[maxn], tot;
阅读全文
摘要:View Code #include<stdio.h>#include<string.h>#define maxn 504#define maxm 100003#define inf 1000000000int min(int a, int b){ return a < b ? a : b;}int max(int a, int b){ return a > b ? a : b;}struct E{ int v, next, c;}edge[maxm];int head[maxn], tot;int n, m;int S, T;int s, t;void i
阅读全文
摘要:View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define maxn 410#define maxm 40003#define inf 1000000000int min(int a, int b){ return a < b ? a : b;}struct E{ int v, next, c;}edge[maxm];int head[maxn], tot;int n, m;int S, T;void add(int s, int
阅读全文
摘要:每条边的容量满足一定的限制,即有一个上限值,也有一个下限值上界用ci表示,下界用bi表示。下界是必须流满的,那么对于每一条边,去掉下界后,其自由流为ci– bi。主要思想:每一个点流进来的流=流出去的流对于每一个点i,令Mi= sum(i点所有流进来的下界流)– sum(i点所有流出去的下界流)如果Mi大于0,代表此点必须还要流出去Mi的自由流,那么我们从源点连一条Mi的边到该点。如果Mi小于0,代表此点必须还要流进来Mi的自由流,那么我们从该点连一条Mi的边到汇点。如果求S->T的最大流,看是否满流(S的相邻边都流满)。满流则有解,否则无解。View Code #include<
阅读全文
摘要:View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define maxn 803#define maxm 10003#define inf 1000000000int min(int a, int b){ return a < b ? a : b;}struct E{ int v, next, c;}edge[maxm<<2];int head[maxn], tot;int n, m, s, t;void add(int
阅读全文
摘要:View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define maxn 410#define maxm 40003#define inf 1000000000int min(int a, int b){ return a < b ? a : b;}struct E{ int v, next, c;}edge[maxm];int head[maxn], tot;int n, m;void add(int s, int t, int c
阅读全文
摘要:View Code #include<stdio.h> #include<string.h> const int maxn = 20100; const int maxm = 200200; const int inf = 1<<29; struct node { int v, c, next; }edge[maxm*6]; int head[maxn], tot; int n, m; void init() { int i; for(i = 0; i <= n+2; i++) head[i] = -1; tot = 0; } voi...
阅读全文
摘要:1062* 昂贵的聘礼 枚举等级限制+dijkstra1087* A Plug for UNIX 2分匹配1094 Sorting It All Out floyd 或 拓扑1112* Team Them Up! 2分图染色+DP1122 FDNY to the Rescue! 最短路1125 Stockbroker Grapevine FLOYD1128 Frame Stacking 拓扑排序1135 Domino Effect 最短路 1149* PIGS 网络流1161* Walls Floyd1192 最优连通子集1201 Intervals 差分约束1236* Network of
阅读全文
摘要:为什么要拆点:2 410 0 0 0 110 0 0 0 010 0 1 1 110 0 1 1 1拆点10, 不拆点20做最大流的题目无非是这两步。1.建图2.套sap+gap优化的模板View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define maxn 106#define inf 1000000000int min(int a, int b){ return a < b ? a : b;}struct E{ int v, n
阅读全文
摘要:入门:http://blog.csdn.net/accry/article/details/6070626View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define maxn 50005struct point{ int x, y;}p[maxn], res[maxn<<1];int max(int a, int b){ return a > b ? a : b;}int xmult(point o, point a,
阅读全文
摘要:题意:有n个(n<=1000)城市,告诉坐标(int),边的权值就是两点的距离,并且每个城市都有人居住,现在要修路n-1条路,使得每个城市都连通。现能让一条边可以不用任何花费。求 这条边的两端点的总人数/(包含这条边的最小生成树的总权值-这条边的权值)最大值。即(Wa+Wb)/(mst-w(a,b))最大。思路:先求该图的最小生成树,prim,O(n^2);方法一: 枚举边枚举最小生成树的每条边,去掉这条边,最小生成树变成了2个各自连通的树,假设为树A,B。分别找到树A,B中人口最多的两个点,这两个点连起来就是去掉这条边所取得的最大比例。用树形DP可以求这个最大比例。方法二: 枚举点在求
阅读全文
摘要:题意:一个N个点的无向图,先生成一棵最小生成树,然后给你Q次询问,每次询问都是x,y,z的形式, 表示的意思是在原图中将x,y之间的边增大(一定是变大的)到z时,此时最小生成数的值是多少。最后求Q次询问最小生成树的平均值。 N<=3000 , Q<=10000思路:先求出该图的最小生成树,用prim(), O(n^2)。对于每次询问, 都是将a,b之间的边增加到c, 会出现 两种情况:1. 如果边权增加的那条边原先就不在最小生成树中,那么这时候的最小生成树的值不变2. 如果在原最小生成树中,那么这时候将增加的边从原最小生成树中去掉,这时候生成树就被分成了两个各自联通的部分,可以证明
阅读全文
摘要:230A A. Dragons贪心水题View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;struct node{ int x, y;}p[1003];bool cmp(node a, node b){ return a.x < b.x || a.x == b.x && a.y > b.y;}int main(){ int i, j; int n, s; while( ~scanf("%d%d",
阅读全文
摘要:哈哈View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define maxn 300003int vis[maxn];struct node{ int sex, fa, de, DNA; // sex性别,fa父亲节点, de是不是死了;}p[maxn];int a[maxn];int n, m, k;int find(int x){ return p[x].fa == x ? x : p[x].fa = find(p[x].fa);}vo
阅读全文
摘要:树形DP, 2 个dfs。前几天觉得很难,现在可以说是水题了。View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define maxn 10003struct E{ int v, next, w;}edge[maxn<<1];int tot, head[maxn];int n, m;void init(){ tot = 0; memset(head, -1, sizeof(int)*(n+1));}void add(int s,
阅读全文
摘要:4001 模拟题,仔细一点可以1A。我的代码有点长,但思路很清楚。View Code #include<stdio.h>#include<string.h>bool vis[11][11];int dir[4][2] = {1, 0, -1, 0, 0, -1, 0, 1};int d[8][2] = {2, 1, 2, -1, -2, 1, -2, -1, 1, 2, 1, -2, -1, 2, -1, -2};int dd[8][2] = {1, 0, 1, 0, -1, 0, -1, 0, 0, 1, 0, -1, 0, 1, 0, -1};int main(){
阅读全文
摘要:今天比赛因为不会双端队列卡了几道题,今天好好学学。双端队列一般保存2个值, 原数组的下标,数组中的值。View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define maxn 1000003int a[maxn];int n, m;struct Queue{ int pos, val;}que[maxn];void getmin(){ int i; int head = 0, tail = -1; for(i = 0; i < m-1
阅读全文

浙公网安备 33010602011771号