2013年10月31日
摘要: #include #include #include #include using namespace std;const int maxn = 50050;int n;struct Link_cut_tree { int bef[maxn],pre[maxn],next[maxn][2]; void init() { memset(pre,0,sizeof(pre)); memset(next,0,sizeof(next)); } inline void rotate(int x,int kind) { int y,z; ... 阅读全文
posted @ 2013-10-31 00:01 tobec 阅读(213) 评论(0) 推荐(0) 编辑
2013年9月26日
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1281题意:小希和Gardon在玩一个游戏:对一个N*M的棋盘,在格子里放尽量多的一些国际象棋里面的“车”,并且使得他们不能互相攻击,这当然很简单,但是Gardon限制了只有某些格子才可以放,小希还是很轻松的解决了这个问题(见下图)注意不能放车的地方不影响车的互相攻击。所以现在Gardon想让小希来解决一个更难的问题,在保证尽量多的“车”的前提下,棋盘里有些格子是可以避开的,也就是说,不在这些格子上放车,也可以保证尽量多的“车”被放下。但是某些格子若不放子,就无法保证放尽量多的“车”,这样的格子被称做重要点。 阅读全文
posted @ 2013-09-26 23:27 tobec 阅读(296) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1053/***利用优先队列构造霍夫曼树,首先将所有编码出现次数作为叶子节点的权值加入队列,**然后每次取出权值最小的两个节点,组合后加入队列。**最后遍历树求得总的编码长度。*/#include #include #include #include #include #include using namespace std;struct node{ int w; bool yezi;//是否是叶子节点 node *lc,*rc; bool operator Q;//优先队列void H... 阅读全文
posted @ 2013-09-26 23:10 tobec 阅读(236) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1059#include #include #include using namespace std;int a[7];int dp[121111];int v,k;void ZeroOnePack(int cost,int weight) { for(int i=v;i>=cost;i--) dp[i] = max(dp[i] , dp[i-cost] + weight); }void CompletePack(int cost,int weight) { for(int i=... 阅读全文
posted @ 2013-09-26 23:08 tobec 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 很久以前做过很多网络流的题目,今天翻出来但是的小结,放在这里温习一下,同时和大家分享一下。hdu1281题意:小希和Gardon在玩一个游戏:对一个N*M的棋盘,在格子里放尽量多的一些国际象棋里面的“车”,并且使得他们不能互相攻击,这当然很简单,但是Gardon限制了只有某些格子才可以放,小希还是很轻松的解决了这个问题(见下图)注意不能放车的地方不影响车的互相攻击。所以现在Gardon想让小希来解决一个更难的问题,在保证尽量多的“车”的前提下,棋盘里有些格子是可以避开的,也就是说,不在这些格子上放车,也可以保证尽量多的“车”被放下。但是某些格子若不放子,就无法保证放尽量多的“车”,这样的格子被 阅读全文
posted @ 2013-09-26 23:04 tobec 阅读(726) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2108#include#include#include#include#includeusing namespace std;struct point { double x,y; };bool mult(point sp,point ep,point op){ return (sp.x-op.x)*(ep.y-op.y)>=(ep.x-op.x)*(sp.y-op.y);}bool operator =0;i--){ while(top!=len && mult(pnt[i],res[t 阅读全文
posted @ 2013-09-26 23:01 tobec 阅读(162) 评论(0) 推荐(0) 编辑
摘要: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4879把b[][]数组上的每个位拆开成两个点i和i',(不超过32位),另外新加两个点0和1,如果确定某点i对应的是0,则i与0点合并,i'点与1点合并;如果确定某点i对应的是1,则i与1合并,i'与0合并;如果确定两点i和j对应的位是相反的数,则i与j'合并,j与i'合并;如果确定两点对应的位是相同的数,则i与j合并,i'与j'合并。#include #include #include #include using n 阅读全文
posted @ 2013-09-26 23:00 tobec 阅读(202) 评论(0) 推荐(0) 编辑
2013年9月17日
摘要: http://poj.org/problem?id=2337题意:按最字典序最小的顺序输出欧拉路。这道题用的使用中回溯的方法,但是忘记掉叫什么名字了,暂时称其为欧拉路输出算法吧~其核心代码为:void find_eularpath(int u) { int sz = g[u].size(); for(int i=0;i#include #include #include #include #include #include using namespace std;const int N = 26;struct node { int v; bool vis; string na... 阅读全文
posted @ 2013-09-17 16:30 tobec 阅读(228) 评论(0) 推荐(0) 编辑
2013年8月18日
摘要: http://www.lydsy.com/JudgeOnline/problem.php?id=2653题目描述: 给长度为20000的序列。求左端点在[a,b]和右端点在[c,d]中所有的子序列,最大的中位数。#include #include #include #include using namespace std;const int N = 20005;struct info{ int sum, mxl, mxr; info(){} info(int val){ sum = mxl = mxr = val; }};info operator + (... 阅读全文
posted @ 2013-08-18 20:48 tobec 阅读(594) 评论(0) 推荐(0) 编辑
摘要: #include #include #include #include #include using namespace std;const int maxm = 16;const int maxn = 1 e[maxn]; int d[maxn],p[maxn][maxm]; void dfs_(int v,int f) { p[v][0] = f; for(int i=1;i d[b]) { swap(a , b); } b = up_(b , d[b]-d[a]); if(a == ... 阅读全文
posted @ 2013-08-18 12:33 tobec 阅读(367) 评论(0) 推荐(0) 编辑