随笔分类 -  HDU

上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 19 下一页

 
HDU 1068
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1068应用匈牙利算法第三个扩展,求二分图的最大独立集,但由于路径是双向的,所以求出的最大匹配是实际最大匹配数*2,还要再除回去才行,单向路径就没有这个问题#include #include #include usi... 阅读全文
posted @ 2014-04-15 16:18 LegendaryAC 阅读(179) 评论(0) 推荐(0)
HDU 2444
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2444判断是否构成二分图,如果有则求最大匹配二分图判断用染色法,一个dfs就出来,具体看代码#include #include using namespace std ;int n,m ;struct node{ ... 阅读全文
posted @ 2014-04-10 17:37 LegendaryAC 阅读(113) 评论(0) 推荐(0)
HDU 3631
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3631只能走标记过的点,方法是标记哪个点就对哪个点做floyd#include #include #include using namespace std ;const int INF=0xfffffff ;int... 阅读全文
posted @ 2014-04-08 15:47 LegendaryAC 阅读(205) 评论(0) 推荐(0)
HDU 1198
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1198裸并查集,主要工作在根据题目给出关系构图#include #include #include using namespace std ;int idx[2505] ;int m,n ;char M[55][5... 阅读全文
posted @ 2014-04-08 15:44 LegendaryAC 阅读(125) 评论(0) 推荐(0)
HDU 4034
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4034给出最短路,问最少有几条边,floyd加一个变量记录该边是否取如果满足dis[i][k]+dis[k][j]==dis[i][j],那么i到j这条边就不取如果出现dis[i][k]+dis[k][j]#inc... 阅读全文
posted @ 2014-04-07 23:17 LegendaryAC 阅读(235) 评论(0) 推荐(0)
HDU 2807
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2807把矩阵相乘放在第二重循环,第三重循环只进行比较可以水过,优化的方法不懂主要用这题练习floyd的写法#include #include using namespace std ;const int INF=0... 阅读全文
posted @ 2014-04-06 02:38 LegendaryAC 阅读(262) 评论(0) 推荐(0)
斯特灵(Stirling)数
摘要:http://zh.wikipedia.org/wiki/%E6%96%AF%E7%89%B9%E7%81%B5%E6%95%B0第一类:n个元素分成k个非空循环排列(环)的方法总数递推式:s(n+1,k)=s(n,k-1)+n*s(n,k)解释:考虑第n+1个元素 1、单独形成循环排列,剩下的有s(n,k-1)种方法 2、和别的元素一起形成循环排列,n个元素形成循环排列的方法数是s(n,k),第n+1个可以放在第i个元 素左边,共有n种放法,一共是n*s(n,k)代码:memset(str1,0,sizeof(str1)) ;for(int i=1 ;i<=20 ;i++){ st.. 阅读全文
posted @ 2014-04-04 17:05 LegendaryAC 阅读(465) 评论(0) 推荐(0)
HDU 3986
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3986从开始的最短路里依次删一条边,求新的最短路,求最长的最短路删边操作要标记节点以及节点对应的边#include #include #include #include using namespace std ;c... 阅读全文
posted @ 2014-03-19 00:55 LegendaryAC 阅读(378) 评论(0) 推荐(0)
HDU 2175
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2175做得好辛苦的一道规律题,至于为什么辛苦。。dont ask me why。。。n号盘子出现的位置是(1,3,5,7......)*2^(n-1)#include using namespace std ;typedef __int64 ll ;int main(){ ll a[105] ; a[1]=1 ; for(int i=2 ;i<64 ;i++) a[i]=a[i-1]*2 ; ll n,m ; while(~scanf("%I64d%I64d",&n... 阅读全文
posted @ 2014-03-14 23:15 LegendaryAC 阅读(203) 评论(0) 推荐(0)
HDU 2323
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2323把六边形抽象成坐标进行dp,抽象出的坐标关系必须满足六边形之间的关系。很有趣的一道dp#include using namespace std ;int dp[25][25][25] ;int main(){ dp[0][7][7]=1 ; for(int i=1 ;i<=14 ;i++) { for(int j=0 ;j<=14 ;j++) { for(int k=0 ;k<=14 ;k++) dp[i]... 阅读全文
posted @ 2014-03-09 21:25 LegendaryAC 阅读(182) 评论(0) 推荐(0)
两道差分约束
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1384#include #include #include #include using namespace std ;const int INF=0xfffffff ;int vis[50005],dis[500... 阅读全文
posted @ 2014-02-23 15:20 LegendaryAC 阅读(150) 评论(0) 推荐(0)
HDU 1452
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1452原来真心没见过这种题,不会做,非常帅gcd(a,b)==1 && s(a,b)==s(a)*s(b)满足这种条件的s叫做积性函数,本题求的因子和就是一个积性函数接着有一个结论if(prime[p])s(p^n)=1+p^1+p^2+p^n=(p^(n+1)-1)/(p-1)s(2004^n)=s(2^(2n))*s(3^n)*s(167^n)其中,167和22关于29同余所以,s(2004^n)=s(2^(2n))*s(3^n)*s(2^n)a=s(2^(2n))=(2^(2n+1)-1 阅读全文
posted @ 2014-01-29 07:41 LegendaryAC 阅读(510) 评论(0) 推荐(0)
HDU 2665
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2665在线询问静态区间k大去学主席树,没看懂;学树套树,没看懂;最后划分树拯救了我,orz......划分树讲解看百度百科#include #include using namespace std ;int tree[30][100005] ;int toleft[30][100005] ;int sorted[100005] ; void build(int l,int r,int dep){ if(l==r)return ; int m=(l+r)>>1 ; int same=m-l+1... 阅读全文
posted @ 2014-01-26 18:07 LegendaryAC 阅读(211) 评论(0) 推荐(0)
HDU 1806
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1806非常玄妙的rmq问题,这个st算法有点神#include #include using namespace std ;int dp[100005][20] ;int a[100005],b[100005] ;void makermq(int n,int *tt){ for(int i=0 ;i>1 ; if(a[mid]>temp) r=mid-1 ; else if(a[mid]=0 ;i--) { if(i=... 阅读全文
posted @ 2014-01-23 21:55 LegendaryAC 阅读(195) 评论(0) 推荐(0)
HDU 1043
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1043http://www.cnblogs.com/goodness/archive/2010/05/04/1727141.html根据这篇文章说的八数码八境界,我这种做法大概是在境界三。。我选择的是康托展开作为哈希函数,在全排列问题中这个哈希函数可以很好的处理冲突http://zh.wikipedia.org/zh/%E5%BA%B7%E6%89%98%E5%B1%95%E5%BC%80当然白书上的那种哈希也是极好的。。#include #include #include using namespace s 阅读全文
posted @ 2014-01-23 10:15 LegendaryAC 阅读(650) 评论(0) 推荐(0)
HDU 1073
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1073模拟oj判题随便搞,开始字符串读入的细节地方没处理好,wa了好久#include #include #include #include using namespace std ; char s1[100005... 阅读全文
posted @ 2014-01-18 23:29 LegendaryAC 阅读(290) 评论(0) 推荐(0)
两个二分
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4190二分答案#include using namespace std ;int a[500005] ;int main(){ int n,b ; while(~scanf("%d%d",&n,&b),n!=-1) { int maxn=-1 ; for(int i=0 ;i>1 ; int sum=0 ; for(int i=0 ;ib) left=mid+1 ; e... 阅读全文
posted @ 2014-01-17 22:16 LegendaryAC 阅读(163) 评论(0) 推荐(0)
HDU 3378
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3378规则去玩三国杀就理解了纯模拟注意的点:有已经分出胜负但还在杀的情况出现,所以要每次杀操作前判断是否分出胜负,如果已经分出胜负了就continue,不用接着往下操作#include #include #include using namespace std ;int n ;typedef struct L{ char js[5] ; int al ; int esc ; int sc ;}L ;L kk[101] ;int pk ;int bjnj,wnj ;int ok(){ ... 阅读全文
posted @ 2014-01-05 04:27 LegendaryAC 阅读(281) 评论(0) 推荐(0)
HDU 1374
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1374已知三点坐标,求三点确定的圆的周长#include #include #include using namespace std ;//由正弦定理 sin90°/d=sinA/a 既d=a/sinA //s=1/2(bcsinA) 既sinA=2s/bc //由海伦公式 s=sqrt(p(p-a)(p-b)(p-c)),p=(a+b+c)/2 #define PI 3.141592653589793int main(){ double x1,y1,x2,y2,x3,y3 ; while(~sc. 阅读全文
posted @ 2013-12-20 14:47 LegendaryAC 阅读(155) 评论(0) 推荐(0)
HDU 3345
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3345最近重写usaco压力好大,每天写的都想吐。。水一道bfs注意的是开始旁边有敌人可以随便走,但是一旦开始走,再与敌人相邻行动力就变为0#include #include #include #include #include #include #include using namespace std ;char map[101][101] ;char ans[101][101] ;int vis[101][101] ;int n,m,MV ;typedef struct L{ int x,y ; ... 阅读全文
posted @ 2013-12-18 22:51 LegendaryAC 阅读(230) 评论(0) 推荐(0)

上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 19 下一页