09 2012 档案
摘要:呃,感觉题意不是很明白,“由于要在蛋糕上抹奶油,为尽可能节约经费,我们希望蛋糕外表面(最下一层的下底面除外)的面积Q最小。”其实题意是说:所有的外表面+最下层的圆面积。(蛋糕从上往下俯视....只有一个最大的园面) 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <cmath> 6 using namespace std; 7 8 #define inf 999999999 9 #defin
阅读全文
摘要:八数码问题:bfs实现.... 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <string> 5 #include <algorithm> 6 #include <cmath> 7 #include <queue> 8 9 using namespace std; 10 11 #define MAXN 363000 //9!==326880 12 13 struct node 14 { 15 int s[9]
阅读全文
摘要:这里的哈希函数是用能对许多全排列问题适用的方法。取n!为基数,状态第n位的逆序值为哈希值第n位数。对于空格,取其(9-位置)再乘以8!。例如,1 3 7 2 4 6 8 5 8 的哈希值等于:0*0! + 0*1! + 0*2! + 2*3! + 1*4! + 1*5! + 0*6! + 3*7! + (9-8)*8! = 55596 <9! 具体的原因可以去查查一些数学书,其中1 2 3 4 5 6 7 8 9 的哈希值是0 最小,8 7 6 5 4 3 2 1 0 的哈希值是(9!-1)最大,而其他值都在0 到(9!-1)中,且均唯一。例如三个元素的排列排列 逆序Hash123 00
阅读全文
摘要:要不是做这题之前就知道可以用km匹配做的话,估计也想不出最短距离和的匹配一定不会交叉。。。画个图:假如A<->C B<->D匹配后的距离和值最小且交于E.则一定可以得到 A<->D B<->C的匹配的距离和小于A<->C B<->D。矛盾。故最小匹配后一定无交点。Km算法求二分图最优值匹配:注意要用:double。。。明明说了是Each ant colony and apple tree is described by a pair of integer coordinatesxandy(−10 000≤x,y≤10 00
阅读全文
摘要:有N个工件要在M个机器上加工,有一个N*M的矩阵描述其加工时间。同一时间内每个机器只能加工一个工件,问加工完所有工件后,使得平均加工时间最小(等待的时间+加工的时间)。假设某个机器处理了k个玩具,时间分别为a1,a2…..,ak那么该机器耗费的时间为a1+(a1+a2)+(a1+a2+a3).......(a1+a2+...ak) 即a1*k + a2 * (k - 1) + a3 * (k - 2).... + akai玩具在某个机器上倒数第k个处理,所耗费全局的时间为ai*k对每个机器,最多可以处理n个玩具,拆成n个点,1~n分别代表某个玩具在这个机器上倒数第几个被加工的,对于每个玩具i,
阅读全文
摘要:n个人要回到n个屋子,要求最小的花费。KM算法可以求二分图最大权匹配,求最少花费可以先对距离取负数,求最大,再取负数即可。ps:km算法看的还不是很懂啊《《《》》 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 6 using namespace std; 7 8 #define MAXN 110 9 #define inf 999999999 10 11 struct point 12 { 13 int x,y; 14
阅读全文
摘要:poj 3692View Code 1 //POJ3692 2 //匈牙利算法,二分图的最大匹配 3 //最大完全数:最大完全子图中顶点的个数 最大完全数=原图的补图的最大独立数 4 5 #include <iostream> 6 #include <cstdio> 7 #include <cstring> 8 9 using namespace std;10 11 #define MAXN 21012 13 int nx,ny;14 bool vis[MAXN];15 int map[MAXN][MAXN];16 int link[MAXN];//第y个点
阅读全文
摘要:原文地址:http://imlazy.ycool.com/post.1603708.html什么是二分图,什么是二分图的最大匹配,这些定义我就不讲了,网上随便都找得到。二分图的最大匹配有两种求法,第一种是最大流(我在此假设读者已有网络流的知识);第二种就是我现在要讲的匈牙利算法。这个算法说白了就是最大流的算法,但是它跟据二分图匹配这个问题的特点,把最大流算法做了简化,提高了效率。匈牙利算法其实很简单,但是网上搜不到什么说得清楚的文章。所以我决定要写一下。最大流算法的核心问题就是找增广路径(augment path)。匈牙利算法也不例外,它的基本模式就是:初始时最大匹配为空while 找得到增广
阅读全文
摘要:题意:给你一个区间[l,r],要求sum(x-xi)(l<=i<=r)的最小值,其中x必须为xl,xl+1...xr中的一个数当x为[l,r]的中位数的时候,满足要求。求任意区间的中位数可以用划分树(k-number)来解决,同样的,我们用suml[d][i]来记录划分树中第d层到数i位置放入左子树的数字的和,具体见代码: 1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cstring> 5 using namespace std
阅读全文
摘要:1 //hdu 2665 2 #include <iostream> 3 #include <cstdio> 4 #include <algorithm> 5 #include <cstring> 6 7 using namespace std; 8 9 #define ls rt<<1 10 #define rs rt<<1|1 11 #define lson l,m,ls 12 #define rson m+1,r,rs 13 14 #define MAXN 100010 15 16 int len; 17 int s
阅读全文
摘要:唉,比赛的时候怎么都不会啊!!题解:http://blog.csdn.net/acm_cxlove/article/details/8014170划分树+二分答案:划分树可以方便的求解k-number。再利用二分答案,即区间内小于h的个数(最大为r-l+1,最小为0)。 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 6 using namespace std; 7 8 #define ls rt<<1 9
阅读全文
摘要:1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <map> 6 7 using namespace std; 8 9 #define MAXN 3001010 11 __int64 sum[MAXN];12 int a[MAXN];13 map<int,int> hash;14 15 struct node16 {17 int id,l,r;18 }tree[100010];19
阅读全文
摘要:1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 7 using namespace std; 8 9 #define mid (l+r)>>110 #define ls rt<<111 #define rs rt<<1|112 #define lson l,m,rt<<113 #define rson m+1,r,rt<
阅读全文
摘要:1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 #include <algorithm> 5 6 using namespace std; 7 8 #define maxn 100005 9 10 struct blo11 {12 int w;13 int d;14 }block[maxn];15 16 bool cmp(const blo&a,const blo&b)17 {18 return a.w+a.d<b.w+b.d;19 }20 2
阅读全文
摘要:题意:求从一个点s 到 一点 e 经过 n 条边的最短路经是多少(可以有重边)贴一个floyd算法讲解:http://blog.csdn.net/niushuai666/article/details/6772706以前一直没仔细想过floyd算法,觉得很简单,今天做这题的时候,看网上的报告都有一句:floyd是每次使用一个中间点k去更新i,j之间的距离,那么更新成功表示i,j之间恰有一个点k时的最短路,如果做N - 1次floyd那么不就是i,j之间借助N - 1 个点时的最短路了。看了很久不明白为什么。也对floyd的最外围的那个k<n产生了疑惑。后来突然想到了,floyd每次更新的
阅读全文
摘要:终于在9.1号这个开学第一天刷到300题了。虽然我们开学好几天了,慢慢的刷,慢慢的学习也终于到300了。昨天cf的题真的很水,可是各种错啊,,唉,不然说不定都变蓝了。呵呵,这也好,慢慢来,从比赛中学习,以后看题的时候得看仔细了,看题不仔细导致思路错误+wa的时间比写的慢浪费的时间多太多了。。必须得细心,认真啊。细节决定成败。当个教训。以后一定记住要稳。
阅读全文