随笔分类 -  2012-Multi

摘要:一开始就想到了扩展KMP,因为只有扩展KMP才是处理后缀的。但忽然短路以为扩展KMP求的是最长公共后缀,囧。。。。又浪费了很多时间,都是对这个算法练得不多再看那个扩展KMP算法之后,就很确定要的就是这个算法了。嗯,如果直接用扩展KMP,是会超时的。后来看了别人一个很巧妙的处理,把一个串复制一下两个串... 阅读全文
posted @ 2014-11-22 16:12 chenjunjie1994 阅读(165) 评论(0) 推荐(0)
摘要:顶好的一道题。其实,是POJ 2411的升级版。但POJ 2411我用的插头DP来做,一时没想到那道题怎么用状态DP,于是回头看POJ 2411那一道的状态DP,其实也很简单,就是每一行都设一个状态,用位来表示,如果上一行为0,则当前行必定是要竖着放的。填1.否则,当前行的位置可以横放填两个格子为1... 阅读全文
posted @ 2014-11-22 11:34 chenjunjie1994 阅读(129) 评论(0) 推荐(0)
摘要:一个很直观的想法是,求出每个点上下左右能到达的最大长度。然后枚举其斜边。。。没想到过了。。。。当然,题解有一个很巧妙的优化,利用树状数组,那个太巧妙了。#include#include#include#include#include#includeusing namespace std;int t,... 阅读全文
posted @ 2014-11-15 19:53 chenjunjie1994 阅读(186) 评论(0) 推荐(0)
摘要:三个摄像头,在XOY上与立体的点求出在平面上的交点,然后求出凸包。三个凸包相交的面积即是所求,即是可以用半平面交的方法求解了。模板题了。代码拿别人的。#include#include#include#includeusing namespace std;const int mm=111;typede... 阅读全文
posted @ 2014-11-12 21:10 chenjunjie1994 阅读(211) 评论(0) 推荐(0)
摘要:悬线法可解,稍有点烦琐。#include #include #include #include using namespace std;char map[1010][1010];int lefts[1010][1010],heights[1010][1010],rights[1010][1010];... 阅读全文
posted @ 2014-11-12 20:44 chenjunjie1994 阅读(167) 评论(0) 推荐(0)
摘要:果然换个编译器就过了。总的来说,不难,不过就是处理一些空格。学习了一个新的类 istringstream可以按空格划分。然后,那条式子要理解。式子的意义是:找到一个串,该串在query中是第几个找到/它的实际位置。之和再除以给出的有几个串就是AVEP#include #include #includ... 阅读全文
posted @ 2014-11-10 16:18 chenjunjie1994 阅读(135) 评论(0) 推荐(0)
摘要:http://www.cnblogs.com/staginner/archive/2012/08/13/2636826.html自己看过后两周吧,重新写了一遍。很受启发的。对于0、1,可以使用最小割的思想来做,以前有听说过0、1规划的问题,估计就是这样的了。对这个题目使用最小割 ,是一个非常巧妙的思... 阅读全文
posted @ 2014-11-10 09:39 chenjunjie1994 阅读(241) 评论(0) 推荐(0)
摘要:很明显的区间加减单点查询。但由于规模大,于是离散化。在离散化的时候,可以把要查询的点也加入离散化的数组中。#include #include #include #include #define lowbit(x) ((x)&(-x))#define LL __int64using namespace... 阅读全文
posted @ 2014-11-09 22:11 chenjunjie1994 阅读(128) 评论(0) 推荐(0)
摘要:直接DFS即可#include #include #include #include using namespace std;bool vis[2010];char map[2010][2010];struct e{ int u,v; int next;}edge[2050000];int head... 阅读全文
posted @ 2014-11-09 20:30 chenjunjie1994 阅读(118) 评论(0) 推荐(0)
摘要:编辑距离,经典的了。动态规划枚举即过。#include #include #include #include using namespace std;char bgn[1505][15];char tmp[15];int dp[15];int main(){ int T,n,m,kase=0,e,c... 阅读全文
posted @ 2014-11-09 18:02 chenjunjie1994 阅读(180) 评论(0) 推荐(0)
摘要:题意:给定a和b,n,让你求b+a, b+2*a, .......b+n*a里面有多少1.当统计第K位的时候 可以注意到 第 B+T*A 和 B+(T+2^(K+1))*A 位是相同的那么 第K位的时候 只需要统计2^(K + 1) - 1次就可以了 当统计第K位的时候 可以注意到 连续的 (2^K... 阅读全文
posted @ 2014-11-09 16:33 chenjunjie1994 阅读(262) 评论(0) 推荐(0)
摘要:只需A的全部质因数包含在B中即可。#include #include #define LL __int64#include using namespace std;LL gcd(LL a,LL b){ if (b==0) return a; return gcd(b,a%b);}int main()... 阅读全文
posted @ 2014-11-09 09:39 chenjunjie1994 阅读(195) 评论(0) 推荐(0)
摘要:可以知道,逃出的人中,最后一个应当是A+B最长的,这是很容易发现的。那么,最选逃出去的必定是A+B最短的。这符合最优。于是,可以把各小矮人按A+B的和由大到小排序。定义DP[i][j]为i个人中逃出了j个人至少需要“之前”的留在井中的未逃出去的小矮人的高度和。注意这个值是可以为负数的,是负数,则证明... 阅读全文
posted @ 2014-11-01 15:31 chenjunjie1994 阅读(200) 评论(0) 推荐(0)
摘要:很明显的树形DP了。但网上有的说可以用并查集。。。。考虑一棵子树,当根结点有机器人时,则必定所有子树都要和根结点断开,而根结点向上返回的路径值则为其父结点与根结点连边的权值。当根结点安全时,假设其子树有K个危险结点,而由于K个结点需要两两不能相连,那么,至少断开K-1个结点。则把权值最小的K-1断开... 阅读全文
posted @ 2014-11-01 15:21 chenjunjie1994 阅读(160) 评论(0) 推荐(0)
摘要:简单的一题,使用类DIJK的算法就可以了。#include #include #include #include using namespace std;struct Edge{ int u,v; double lose; int next;}edge[2500050];int head[50010... 阅读全文
posted @ 2014-11-01 11:39 chenjunjie1994 阅读(165) 评论(0) 推荐(0)
摘要:题目要求两点间的最大值作为距离即:即是切比雪夫距离。而切比雪夫距离与曼哈顿距离的转换却很巧妙。把平面坐标所有点绕原点逆向旋转45度后,所得点的曼哈顿距离之和除以√2,即是切雪比夫距离。旋转点的公式是提取无理数,即每个新坐标可以是(x-y,x+y)。计算其曼哈顿距离后除以2即可。#include #i... 阅读全文
posted @ 2014-10-29 16:22 chenjunjie1994 阅读(221) 评论(0) 推荐(0)
摘要:求的是曼哈顿距离。可以把X,Y的距离分开来求。其中,求X、Y的距离可以通过排序后递推的方式求出值的。#include #include #include #include #define LL __int64using namespace std;struct point{ int x,y; int... 阅读全文
posted @ 2014-10-29 15:30 chenjunjie1994 阅读(111) 评论(0) 推荐(0)
摘要:贪心,注意排序条件。#include #include #include using namespace std;const int N=25;struct En{ int DSP,HP;}E[N];bool cmp(En a,En b){ if(a.DSP*1.0/a.HP>b.DSP*1.0/b... 阅读全文
posted @ 2014-10-27 18:37 chenjunjie1994 阅读(150) 评论(0) 推荐(0)
摘要:最大流建图。开始以为旧桥有1000座,没敢用枚举,后来看看题目发现了只是十二座。枚举桥的状态没问题。对于隧道的容量W,可以虚拟出第三个结点表示,如u->v。增加一个点p,u->p(INF),p->v(INF),p->End(W);#include #include #include #include... 阅读全文
posted @ 2014-10-25 21:35 chenjunjie1994 阅读(168) 评论(0) 推荐(0)
摘要:纯BFS+优先队列扩展。 #include #include #include #include #include using namespace std; bool vis[5100]; char str[5100]; struct point{ int x,y; int cos... 阅读全文
posted @ 2014-10-25 19:38 chenjunjie1994 阅读(135) 评论(0) 推荐(0)