Algorithm------分割线
Falling~
这个作者很懒,什么都没留下…
展开
-
尺取法
使k个连续数之和大于等于s,求k最小值原创 2017-02-25 14:00:14 · 314 阅读 · 0 评论 -
Havel定理
Havel定理描述给定一个非负整数序列{d1,d2,...dn},若存在一个无向图使得图中各点的度与此序列一一对应,则称此序列可图化。进一步,若图为简单图,则称此序列可简单图化。可图化的判定比较简单:d1+d2+...dn=0(mod2)。关于具体图的构造,我们可以简单地把奇数度的点配对,剩下的全部搞成自环。可简单图化的判定,有一个Havel定理,是说: 我们把序列排成转载 2017-06-15 18:32:15 · 441 阅读 · 0 评论 -
分解阶乘中某个因子个数
m天做n题。x1 + x2 + ... + xm = n;(xi >= 0)y1 + y2 + ... + ym = m + n(yi >= 1)即C(m + n - 1,m - 1) = C(m + n - 1,n)#include #include using namespacestd;typedef longlong ll;原创 2017-06-02 15:13:37 · 442 阅读 · 0 评论 -
PAT1010 Radix
PAT的题真是。。//1.虽然字母只到z,但是进制最大并不止35,那就真的可能超long long了//2.一个点会超时,二分,//我果然太天真了,还在100左右试,人家进制直接开到num + 1,可是问题就是这样就不是递增的了,怎么能用二分呢#include #include using namespacestd;typedef原创 2017-08-11 10:12:33 · 239 阅读 · 0 评论 -
cf822c Hacker,Pack your bags
给定n个区间,l,r,cost,求其中2个区间是否能凑成总长为x,并且费用最小。没看懂题解,先记录下。从左往右遍历,遇到左端点就更新答案,否则更新bestcost[j],长度为j天时的最小费用。ps:n = 2e5 cost = 1e9 max = 2e14需要long long#include #include #include #include原创 2017-08-11 17:29:05 · 280 阅读 · 0 评论 -
位运算--hdu5980 Find Small A
给定n个int数字(4字节),求里面有几个a(acsii 97)acsii 1字节8位,所以将每个数字按字节分成4份即可。#include #include using namespacestd;int main(){ int n; scanf("%d",&n); int t,cn原创 2017-08-18 17:57:00 · 205 阅读 · 0 评论 -
尺取法--cf701c They are everywhere
#include #include #include #include using namespacestd;string s;setchar> st;multisetchar> mst;mapchar,int> cnt;void f(int sz,int n){ int l =0,r =原创 2017-07-27 19:54:06 · 329 阅读 · 0 评论 -
矩阵快速幂取模--cf678d Iterated linear function
所有线性变换可由矩阵表示。#include using namespacestd;const int mod =1e9 + 7;struct matrix{ long long m[2][2];};long long a,b,n,x;matrix multiple(matrix a,matrix b)原创 2017-07-27 21:36:16 · 331 阅读 · 0 评论 -
整除7,9,11的数的性质
1.能被9整除的数,各个位之和能被9整除。2.能被11整除的数,奇数位数字之和与偶数位数字之和的差,能被11整除。3.一个3位以上的数字,能被7(9或11)整除的特征是,a = 他的后三位,b = 除了后3位以外的数字,两者差的绝对值能被7(9或11)整除。原创 2017-06-09 21:18:24 · 2499 阅读 · 0 评论 -
翻转--开关问题
详情见挑战p150-156poj 3276#include #include #include using namespace std;const int maxn =5000 + 5;int dir[maxn];int f[maxn];//f[i] = f[i,i + k - 1]是否翻转int n;原创 2017-08-22 10:31:18 · 342 阅读 · 0 评论 -
给定n个数,求其中4个数的和是否能为0
设a #include #include #include #include using namespacestd;const int maxn =1000 + 2;int num[maxn];int main(){ int n; scanf("%d",&n);原创 2017-07-25 21:15:34 · 320 阅读 · 0 评论 -
贪心
在重叠区间中取最少点,使所有区间中都有点。原创 2017-04-04 20:44:51 · 185 阅读 · 0 评论 -
大数加法
大数加法原创 2017-04-21 13:51:55 · 271 阅读 · 0 评论 -
大数减法
#include #include #include #include using namespacestd;const int maxn =10005;void trans(string s,vectorint> &v,int fg){ v.clear(); for (int i = s.size()原创 2017-05-25 14:04:24 · 254 阅读 · 0 评论 -
hdu1722--cake
一次生日Party可能有p人或者q人参加,现准备有一个大蛋糕.问最少要将蛋糕切成多少块(每块大小不一定相等),才能使p人或者q人出席的任何一种情况,都能平均将蛋糕分食. 分析:1.将蛋糕看作直线例,3、5,要分为3份,在5,10,15处分割;分为5份,在3,6,9,12,15处分割。要同时3、5等分,就在5,10,15,3,6,9,12共7处分割。2.p、q,要分为p份,在p,转载 2017-06-17 19:05:12 · 201 阅读 · 0 评论 -
模的应用--uva11582 Colossal Fibonacci Numbers!
For each test case, output a single line containing the remainder off(ab) upon division byn. 0 ≤ a,b 264(aand bwill not both be zero) and1 ≤n ≤1000. 思想很巧妙,求f(a ^ b)原创 2017-05-22 21:11:44 · 187 阅读 · 0 评论 -
尺取法--An impassioned circulation of affection
cfR418-c6koyomi31 o4 o4 mq个问讯,每次可以repaint m个字符变成c,求最长连续的字符全为c的长度。连续,可以用尺取。#include #include #include using namespacestd;string s;int n;void solve(int m,cha原创 2017-06-08 19:36:10 · 281 阅读 · 0 评论 -
异或运算的性质
1.若a为任意非负偶数,b为a+1,则a ^ 1 = b,b ^ 1 = a。适合用于处理两两配对问题(如正边,双向边)。e.g. 0 ^ 1 = 1, 1 ^ 1 = 096 ^ 1 = 97,97 ^ 1 = 962.自反性a ^ x ^ x = ax ^ x = 03.0与任何数异或都为那个数0 ^ x = x转载 2017-07-22 14:02:48 · 455 阅读 · 0 评论 -
矩阵快速幂
A为一个方阵,则Tr A表示A的迹(就是主对角线上各项的和),现要求Tr(A^k)%9973#include #include #include using namespacestd;const int mod =9973;struct matrix{ long long num[12][12];};ma原创 2017-05-22 19:35:04 · 192 阅读 · 0 评论 -
贪心--cf478-c Table Decoration
a,b,c3种气球,给定个数,每张桌子放3个,要求一张桌子上颜色不完全相同。设个数 a 2 * (a + b),即acc,bcc,放完仍有剩余,则余下的c多余,可扔掉。c' = min(c,2 * (a + b) )。 组数为 a + b除去c过多的情况,剩下的情况中可以保证所有的气球都用完。组数就为(a + b + c) / 3因为,比如c少一些,c 只要不出现bbb即可。若出原创 2017-07-24 09:59:10 · 294 阅读 · 0 评论 -
欧拉回路--输出欧拉回路的路径
//有向or无向均可,重边step1:从u开始,找到与他相连的v,放入栈,删除(u,v)这条边,然后从v开始step2:当有一点没有与他相连的点时,放入path,然后从stack取栈顶继续开始找点删边。最后记得把栈里的点放到path中。path倒序输出#include #include #include #include原创 2017-09-16 10:11:41 · 1414 阅读 · 0 评论