10 2014 档案
HDU 1026
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1026记录bfs路径,用一个数组记录next前驱的方向,然后递归的时候减回去即可#include #include #include #include using namespace std ;const int ...
阅读全文
HDU 1080
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1080二维最长公共子序列#include #include #include using namespace std ;char s1[105],s2[105];int tab[5][5]={{5,-1,-2,-1...
阅读全文
HDU 1054
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1054二分图最少顶点覆盖,模板题,双向边最后结果/2#include #include #include using namespace std ;struct node{ int s,t,nxt ;}e[1...
阅读全文
HDU 1044
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1044代码题,没什么好说的,先预处理出两点间距离,然后dfs搜一下找最大值#include #include #include #include using namespace std;const int INF=...
阅读全文
HDU 1052
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1052田忌赛马本质就是一个贪心res表示田忌的胜利场次1、田忌最快马快于王的最快马,两个最快马比,res++2、田忌最快马慢于王的最快马,田忌的最慢马和王的最快马比,res--3、田忌最快马等于王的最快马,分三种情...
阅读全文
HDU 1053 & HDU 2527 哈夫曼编码
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1053#include #include #include #include #include using namespace std; int a[30];char s[1005];int cal(char ...
阅读全文
HDU 1069
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1069题意:n种木块问最多可以摆多高,每种有无数个,上面木块的长宽必须分别小于下面木块的长宽注意到每种无数个这个条件是虚的,其实只有三种。dp[i]表示以第 i 块为底可以摆放的最大高度#include #incl...
阅读全文
HDU 1074
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1074状压dp,记录路径求最小值的状压dp非常裸,5分钟就写好了,记录路径有点麻烦,之前没怎么处理过这种问题我的方法是用一个map建立当前状态和前驱状态的映射,输出要按字典序,因为已经按字典序从大到小排好了,所以状...
阅读全文
HDU 5073
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=5073这题的关键是要把p点减重心位置 的 平方的那个式子展开,就可以O(n),开始ans初始化为1e18一直wa,改成1e19就A了最大的部分是连续的,头尾指针一起移动就可以#include #include #i...
阅读全文
HDU 1082
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1082这题开始想复杂了,error并不包括表达式本身不合法的情况我的方法是遇到右括号就开始处理栈,如果开始最外层没有括号,就人为加上数据应该是比较弱的,一通乱搞#include #include #include ...
阅读全文
HDU 5067
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=5067规定起点和终点的tsp问题,解法依然是状态压缩dp,在初始化和计算答案的时候略做改动即可#include #include #include #include using namespace std ;con...
阅读全文
HDU 4856
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4856西安邀请赛的一道题,这道题我们当时在现场最后1h才发现时状态压缩dp,惊险写出现在回头想发现当时有点呆,这种明显tsp模型的题目当时鬼迷心窍去写搜索,超时而不知悔改,实际是水题一道#include #incl...
阅读全文
HDU 3932
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3932一定范围的平面上给一些点,求到这些点的最大距离最小,和上一题的题意正好相反,稍微改一下就可以这个问题又叫最小圆覆盖#include #include #include #include #include #i...
阅读全文
HDU 1109
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1109一个范围内给一堆点,求到这些点的最短距离最大模拟退火,温度是步长#include #include #include #include #include #include using namespace st...
阅读全文
平面点旋转公式
摘要:任意点(x,y),绕一个坐标点(rx0,ry0)逆时针旋转a角度后的新的坐标设为(x0, y0),有公式:x0= (x - rx0)*cos(a)- (y - ry0)*sin(a) + rx0 ;y0= (x - rx0)*sin(a) + (y - ry0)*cos(a) + ry0 ;
阅读全文
HDU 5050
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=5050大数gcdimport java.io.* ;import java.math.* ;import java.util.* ;import java.text.* ;public class Main { ...
阅读全文
HDU 5045
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=5045题意:n个学生m道题,一个n*m的矩阵代表第n个学生解第m题AC的概率,任意两学生做题数差距不能大于1,问AC所有题目概率的最大值由于限制条件,所以一定是以n个学生为单位,一轮一轮的做题,直到做m题为止,这样...
阅读全文
矩阵快速幂
摘要:#define MOD 2008#define Mat 35 //矩阵大小 struct mat{//矩阵结构体,a表示内容,r行c列 矩阵从1开始 int a[Mat][Mat]; int r, c; mat() { r = c = 0; ...
阅读全文
HDU 2157
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2157求A到B经过K个点的方案数http://www.matrix67.com/blog/archives/276 这里面的经典问题8存图的邻接矩阵自乘k次,得到的新矩阵A行B列就是答案#include #inc...
阅读全文
HDU 5009
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=5009题意:一个数列,每个点代表一种颜色,每次选一个区间覆盖,覆盖的代价是区间内颜色种类数的平方,直到覆盖整个数列,求最小花费思路:首先合并颜色相同的点,接着离散化颜色,做dp,dp[i]表示取到位置i的最小花费,...
阅读全文
上下界网络流模型常见解法
摘要:一、无源汇可行流1、设立虚拟源汇S、T,IN[i]记录i点流入下限的总和,OUT[i]记录i点流出下限总和2、两点间连容量为上限-下限的边3、sum=0,遍历所有点i,f=IN[i]-OUT[i]。如果f>0,sum+=f,add(S,i,f);否则,add(i,T,-f)4、如果S到T的最大流等于...
阅读全文
|