- 博客(70)
- 收藏
- 关注
原创 轮廓线 离散化+大顶堆
题目: 给定n座建筑物 B[1, 2, … , n],每个建筑物 B[i]表示为一个矩形,用三元组B[i]=(a_i,b_i,h_i)表示,其中a_i表示建筑左下顶点,b_i表示建筑的右下顶点,h_i表示建筑的高,请设计一个 O(nlogn)的算法求出这n座建筑物的天际轮廓。例如,左下图所示中8座建筑的表示分别为(1,5,11), (2,7,6), (3,9,13), (12,16,7),(14,...
2018-10-11 13:37:07
1254
原创 中国剩余定理 不互质
然,对于不互质的情况,同样可以用它来解。将方程组合并。推导如下 取两方程组 {x = n1*k1 + a1 ; {x = n2*k2 + a2 ; 目标合成为x = n*k + a; 有n1*k1+a1 = n2*k2 + a2 ; 设d = gcd(n1,n2) ; 则有(n1*k1)/d - (n2*k2)/d = (a2-a1)/d; I a:当且仅当 d|(a2-a1) ,
2016-07-15 17:59:40
1251
原创 UVa10003 cutting sticks
区间dp,基本裸题 dp[i][j] = dp[i][k] + dp[k][j] + val(j-i) ; 枚举给定的点即可#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#define min(a,b) (a<b?a:b)#define FOR(a,i,b) for( i = a ; i
2016-07-15 17:57:06
367
原创 中国剩余定理CRT (互质)
中国剩余定理给出了以下的一元线性同余方程组: 有解的判定条件,并用构造法给出了在有解情况下解的具体形式。 中国剩余定理说明:假设整数m1,m2, … ,mn两两互质,则对任意的整数:a1,a2, … ,an,方程组 有解,并且通解可以用如下方式构造得到: 设M是整数m1,m2, … ,mn的乘积,并设Mi是除了mi以外的n- 1个整数的乘积。 设为Mi^-1模mi的数论倒数 : 方
2016-07-15 17:40:52
1318
原创 lucas定理
Lucas 适合大组合数取模。 Lucas定理是用来求 c(n,m) mod p,p为素数的值。 时间复杂度O(logp(n)*p): 表达式C(n,m)%p=C(n/p,m/p)*C(n%p,m%p) 重新证明一遍: 令n=sp+q , m=tp+r .(q ,r ≤p) 原式子=C(sp+q,tp+r)%p (1+x)^nΞ(1+x)^(sp+q)Ξ(1+x)^(sp)*(1+x
2016-07-13 11:37:16
542
原创 HDU3939Sticks and Right Triangle勾股数,容斥,欧拉筛,积性函数
若(a, b, c) 三者互质(它们的最大公因数是 1),它们就称为素勾股数。 勾股数的构造: a = m*m-n*n b = 2m*n c = m*m+n*n 若 m 和 n 是互质,而且 m 和 n 其中有一个是偶数,计算出来的 (a, b, c) 就是素勾股数。(若 m 和 n 都是奇数, (a, b, c) 就会全是偶数,不符合互质。) 题意:给定L,求不大于L的勾股数(a,b,
2016-07-12 15:34:07
561
原创 miller-rabin
概率型素性测试。可以说是历史上对费马小定理的”误“翻译起源,后逐渐发展而成。费尔马小定理:如果p是一个素数,且0#include <iostream>#include <cstdio>#include <cstdlib>typedef long long ll ;using namespace std ;ll multi(ll a, ll b , ll mod){ ll ans =
2016-07-11 10:15:23
409
原创 poj 2480 Longge's problem
#include<cstdio>inline void prin(const int &n){ printf("%lld\n",n) ;}typedef long long ll ;ll quick_pow(ll n , ll k){ ll ans = 1; while(k){ if(k&1) ans *= n; n*=
2016-07-11 10:04:06
272
原创 BUN16 51640 dp
bunoj%Q#include #include #include #include using namespace std;const int maxn = 1000+100 ;long long a[maxn] ;long long dp[1000][1000] ;int main(){ int t , n , m ; scanf("%d",
2016-06-10 23:03:45
317
原创 Fib 性质 Gcd(f[n],f[m]) = f(gcd(n,m))
a) gcd(fn, fn-1) = 1, for all n b) fm+n = fm+1 fn + fm fn-1 c) if m divides n, then fm divides fn and the ever important Euclidean Algorithm which states: if n=qm+r, then gcd(n,m)=gcd(m,r). Fo
2016-06-07 18:54:20
1528
原创 HDU 2582 f(n)
定理:设,那么的值为 (1)为素数,那么答案就是 (2)有多个素因子,那么答案就是 (3)只有一个素因子,那么答案就是该素因子#include #include #include using namespace std;//int judge(int n){// int tmp = sqrt(n+0.5) ;
2016-06-06 23:40:30
358
原创 hdoj 2685
#include #include using namespace std;int quick(int a, int k ,int mod ){ int ans = 1 ; while(k){ if(k&1) { ans = (ans*a)%mod ; } a *= a; a %= mod
2016-06-05 16:39:36
339
原创 POJ 3233 Matrix Power Series
http://poj.org/problem?id=3233分析表达式,等比矩阵求和sum(k) = A + A^2 + A^3+...A^k . k 太大容易联想到求矩阵高次幂。sum(k-1) + A^k = sum(k) . 有这个特性,构造出矩阵:|A 1| ans[0][0] 每次相乘得到A^x , ans[0][1] 每次把ans[0][0] 项加之
2016-06-05 12:31:24
260
原创 B. Chilly Willy
http://codeforces.com/problemset/problem/248/Be , 看错题。。 找能被2,3,5,7整除的最小的数,要求长度为n 不会推,找的规律#include #include #include #include using namespace std;const int maxx = 100000+10 ;//string s[maxn]
2016-06-02 13:59:02
306
原创 HDU2554
(ai-bi)=i+1all(ai+bi) = (1+2n)2n/2all(ai-bi)=(3+n)n/2#include using namespace std;/*(b1+...+bn) = (n(n+3)/2 + 2n(2n+1)/2 )/2== (5n*n+5*n)/4 5n(n+1)/4(a1+...+an) = ( 3n*n-n)/4 n(3n-1)/4*/
2016-06-01 14:14:47
297
原创 poj 2229
POJ 2229#include <iostream>#include <cmath>using namespace std;/*if n is odd , then f(n) = f(n-1) .because n is odd , add the answer must have at least a 1, and f(n-1) above all solutionselse if
2016-05-31 22:18:07
224
转载 Gauss analysis
//最近一直在做一个数论专题,后期有待整理,先将有关资料收藏下,在学习高斯消元的时候看了czyuan大牛的此文获益匪浅,czyuan的此份模板可以解决大多高斯问题,当然并不是万能的,其中建立矩阵是难点,需要自己琢磨,并且对于方程组是否有解、解的个数以及自由元等问题也需要自己做题慢慢思考,自己做了两三道题前前后后在建矩阵以及对一些解的问题在Gauss函数中改了几十次,逐渐摸索,还不算掌握的好,有待再慢
2016-05-30 21:40:57
355
原创 Gauss poj 1222
POJ 1222#include <iostream>#include <cstdio>#include <cmath>#include <cstdlib>using namespace std;//0x11 1x12 1x13 0x14//1x21 0x22 0x23 1x24//0x31 0x32 1x33 0x34//1x41 0x42 0x43 1x44//-> simpl
2016-05-30 21:28:28
345
原创 Gauss poj 1830
POJ1830 开关问题巧用位运算。 对于有效true的影响:0->1 , 1->0 ; 无效false的影响:0->0 , 1->1 ; true ^ 0->1 , true^1->0 ; false^0->0 , false^1->1 ; 已知结果矩阵,和初始矩阵,和关系矩阵。初始矩阵^(关系矩阵*变元) == 结果矩阵 变换-> 变元*(关系矩阵)=初始矩阵^结果矩阵 变元的值
2016-05-30 18:20:02
293
原创 Gauss template
learn from kuangbin#include <iostream>#include <cmath>#include <cstdio>#include <cstdlib>using namespace std;const int maxn = 50;int a[maxn][maxn]; // zeng guangint x[maxn] ; // ans_xint free_x
2016-05-30 14:02:14
352
原创 Generating function
普通篇 HDU1171#include <iostream>#include <cstdio>#include <cstdlib>using namespace std;int t1[8100],t2[8100] ;/*i:第I个表达式j:第j个变量k:乘第i个表达式子(1+x^i + x^2i + ...) */ int main(){ int num[4] ={0}
2016-05-28 18:43:57
304
原创 HDU 5242 Game
Problem DescriptionIt is well known that Keima Katsuragi is The Capturing God because of his exceptional skills and experience in ''capturing'' virtual girls in gal games. He is able to playk ga
2015-09-05 15:57:57
410
原创 HDU 5241 Friends
FriendsTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 556 Accepted Submission(s): 283Problem DescriptionMike has many friends.
2015-09-05 10:24:49
910
原创 HDU 5240 Exam
ExamTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 714 Accepted Submission(s): 360HDU 5240Problem DescriptionAs this term is going
2015-09-05 09:03:46
378
原创 HDU 5237 Base64
Base64Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 545 Accepted Submission(s): 220HDU 5237Problem DescriptionMike does not wan
2015-09-05 09:01:40
606
原创 Codeforces Round #317 [AimFund Thanks-Round] (Div. 2) B. Order Book
B. Order Booktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn this task you need to process a set of stock exchange orders a
2015-08-23 08:38:01
823
原创 POJ 2533 Longest Ordered Subsequence
Longest Ordered SubsequenceTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 39246 Accepted: 17258DescriptionA numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subseq
2015-08-22 23:38:01
287
原创 UVa 11624 Fire!
11624 Fire!Joe works in a maze. Unfortunately, portions of the maze have caughton fire, and the owner of the maze neglected to create a fire escape plan.Help Joe escape the maze.Given Joe’s lo
2015-08-22 22:44:27
402
原创 HDU 2612 Find a way
Find a wayTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)HDU 2612 传送Problem DescriptionPass a year learning in Hangzhou, yifenfei arrival hometown Ni
2015-08-22 22:24:24
235
原创 HDU 5115 Dire Wolf 区间DP+记忆化搜索
Dire WolfTime Limit: 5000/5000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)Total Submission(s): 749 Accepted Submission(s): 438Problem DescriptionDire wolves, also known
2015-08-20 16:05:13
368
原创 LightOJ - 1422 Halloween Costumes 区间DP
Halloween CostumesTime Limit: 2000MS Memory Limit: 32768KB 64bit IO Format: %lld & %lluDescriptionGappu has a very busy weekend ahead of him. Because, next weekend is Halloween, and he is plan
2015-08-19 16:53:38
511
原创 HDU 4612 Warm up 树的最长路径DP + 无向图带重边
Warm upTime Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Problem Description N planets are connected by M bidirectional channels that allow instant transporta
2015-08-19 11:33:40
387
原创 HDU 4738Caocao's Bridges 邻接表tarjan 割桥
Caocao's BridgesTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Problem DescriptionCaocao was defeated by Zhuge Liang and Zhou Yu in the battle of Chibi. But
2015-08-15 18:11:05
340
原创 凸包 Graham扫描法
凸包模板函数 Graham扫描法 简单概括就是 排序+扫描#include #include #include #include using namespace std;const int maxn = 20000 ;struct Point { double x,y,len ;}Stack[maxn] , Pt[maxn] , Point_A ;double
2015-08-14 20:29:50
769
原创 ZOJ 3537 Cake 凸包+区间DP+记忆化搜索
Cake--------------------------------------------------------------------------------Time Limit: 1 Second Memory Limit: 32768 KB ------------------------------------------------------------
2015-08-14 19:17:51
422
原创 HDU1160 FatMouse's Speed
FatMouse's SpeedTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)HDU 1160Special JudgeProblem DescriptionFatMouse believes that the fatter a mouse is, the
2015-08-13 20:46:56
228
原创 POJ 2955 brackets
BracketsTime Limit: 1000MS Memory Limit: 65536KDescriptionWe give the following inductive definition of a “regular brackets” sequence:the empty sequence is a regular brackets sequence,if
2015-08-13 20:31:37
303
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人