
ACM
文章平均质量分 76
betwater
博客已迁移,如有问题请访问https://icecory.com
展开
-
数论求逆元的三种方法
扩展欧几里德算法//非递归的扩展欧几里德算法 //返回a、b的gcd,同时x、y满足ax+by=gcd int_t exEuclid(int_t a,int_t b,int_t&x,int_t&y){ int_t x0 = 1, y0 = 0; int_t x1 = 0, y1 = 1; x = 0; y = 1; int原创 2017-03-11 18:29:04 · 1936 阅读 · 0 评论 -
后缀数组 POJ 3693 && hdu 2459 Maximum repetition substring
Maximum repetition substringProblem DescriptionThe repetition number of a string is defined as the maximum number R such that the string can be partitioned into R same consecutive substrings原创 2016-09-01 17:47:20 · 320 阅读 · 0 评论 -
统计数字 1,2,3 ... n 出现 0~9 的个数
http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=10242统计数字问题Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KB Problem 10242 : No special judg原创 2016-10-14 00:29:54 · 5133 阅读 · 0 评论 -
计算几何 BAPC 14 C itadel Construction (Gym 100526C )
题目意思是给定n各点,找四个点,使这四个点围成的面积最大。首先用granham计算最大凸包,然后枚举最大的四边形,但是枚举的时候要注意优化。可以这么考虑,若使四边形abcd面积最大,一定是ac最长的时候,再找最优的b跟d,凑成abcd。 #define SIZE 1001 struct point_t{ llt x,y; }P[SIZE原创 2016-08-25 20:41:24 · 387 阅读 · 0 评论 -
组合数学(斯特林数) hdu 4372 ( Count the Buildings )
给定n栋楼 拍成一列,从前边往后看能看到b栋楼,从后往前能看到f栋楼,问有多少种组合方式.那么最高的那栋楼,肯定是前与后的分界点, 先考虑从前往后看,假设看到了x栋楼, 那么最高楼前面 肯定有x-1 组,每组最高的肯定是在最前面,这样 就只能看到x栋楼。同样后面看到y栋,则最高的后面有y-1组,这样一共就是x-1+y-1组,每组其实又是一个环排列,那么题目可转化为 n-1栋楼求原创 2016-07-31 12:19:05 · 352 阅读 · 0 评论 -
计算几何 点到线段的距离 点在简单多边形内 点到凸多边形的距离
部分内容参考 http://blog.youkuaiyun.com/angelazy/article/details/384892931.点到线段的距离 矢量算法矢量算法过程清晰,如果具有一定的空间几何基础,则是解决此类问题时应优先考虑的方法。当需要计算的数据量很大时,这种方式优势明显。由于矢量具有方向性,故一些方向的判断直接根据其正负号就可以得知,使得其中的一些问原创 2016-09-04 18:58:28 · 6140 阅读 · 1 评论 -
高精度 hdu 2940 Hex Factorial
直接暴力打表,也可以在代码外打表复制粘贴#include#include#includeusing namespace std;const int BIT = 16;struct BIGint{ int bit[200]; void MEMset(){ memset(bit,0,sizeof(bit)); bit[1] = 1;原创 2016-08-11 22:55:57 · 277 阅读 · 0 评论 -
组合数学 polay定理 hud 2409 Let it Bead
典型的polay定理应用先分奇偶的情况,在对称计数的时候会有不同奇数情况,以每个点跟中点作为对称轴,这样会有n/2+1个轮换,因为有n个点,所以要n*pow(c,n/2+1)偶数时,以每个点跟中点在加对称的那个点,这时是n/2+1个轮换,这时是n/2个点,n/2*pow(c,n/2+1),以每条边的中点与中点的连线作对称轴,又是n/2个情况,此时是n/2*pow(c,n/2),原创 2016-08-11 19:54:11 · 573 阅读 · 0 评论 -
计算几何 判断多边形顶点是否是顺时针
1.凸包的时候,只要判断前三个点即可,计算叉积,判断方向2.凹包情况就复杂了,可以从三个方面考虑首先,可以去凸包上的特殊点,x最大最小的点,y最大最小的点,这些极值点肯定是在凸包上的,可以计算这些的叉积,其次,直接统计叉积正负的数量,正多负少,是逆时针,反之,顺时针,一个简单的做法是,计算面积,用面积的正负判断方向http://acm.hunnu.edu.cn/on原创 2016-09-08 23:51:52 · 5759 阅读 · 2 评论 -
数论 FZU 1759 Super A^B mod C
Super A^B mod CTime Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Problem description 计算A^B%C的结果,A^B是指A的B次方。Input 多组测试数据,每组数据仅一行,分别为A,B,C的值。A原创 2016-09-12 20:19:13 · 440 阅读 · 0 评论 -
图论 hdu 5961 传递
传递Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 299 Accepted Submission(s): 130Problem Description我们称一个有向图G是传递的,当且仅当对任意三个不原创 2016-11-06 14:10:19 · 771 阅读 · 0 评论 -
hdu 5974 A Simple Math Problem
A Simple Math ProblemTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 3 Accepted Submission(s): 3Problem DescriptionGiven two原创 2016-11-06 18:26:26 · 1030 阅读 · 0 评论 -
强联通分量 Tarjan算法 模板
/* 图使用向量数组保存,注意初始化edge * 每个点对应的 最大分量的序号 保存在sccNub中 * 可以增加一个vector 存储每个 最大分量中的点 * 所有下标都是 1 ~ n */const int SIZE_N = 10050;vector Edge[SIZE_N];int pre[SIZE_N] , lowlink[SIZE_N] , sccN原创 2016-10-29 15:00:58 · 339 阅读 · 0 评论 -
循环节定理+bsgs 哈尔滨理工ACM程序设计全国邀请赛(网络同步赛) G.Recurring Decimal
G Recurring DecimalDescriptionAs we all know, any scores are can be written in an infinite recurring decimal or a finite decimal ,for example,1/7 can be written in 0.(142857).(recurring peri原创 2016-12-09 20:07:26 · 690 阅读 · 0 评论 -
BSGS 算法 XDoj 1077: 循环节长度
题意很简单,就是给出p,q,求p/q的循环节长度。这里先给一个定理接下来我们只要套用这个定理, 10 ^e = 1 (mod a ) 可以用BSGS算法求得,但是要注意e>0 ,显然e == 0 的时候恒成立#include #include #include #define MOD 76543using namespace std;int hs[MOD], hea原创 2016-12-09 19:35:00 · 848 阅读 · 0 评论 -
所有因子的因子个数的立方和
题目 : 任何一个正整数N,我们可以很容易的找出N的所有因子,N1,N2,N3...,Nk,称N一共有k个因子(包含1和N本身)。求出N所有因子的因子个数(如N1可能包含n1个因子(包含1和N1本身),N2可能包含n2个因子,...,Nk可能包含nk个因子),然后计算出S的值:因为要求出N的因子个数,我们从素数开始讨论。N=1时只有一个因子1,对于任意一个质数p,只原创 2016-11-26 17:59:02 · 909 阅读 · 0 评论 -
贝尔数 hdu4767 (矩阵快速幂+中国剩余定理+bell数+Stirling数+欧几里德)
#include #include typedef long long llt ;typedef long long int_t;using namespace std;/* * 先写好三个模板, 矩阵快速幂 , 扩展欧几里德 , 中国剩余定理 *///非递归的扩展欧几里德算法//返回a、b的gcd,同时x、y满足ax+by=gcdint_t exEuclid(int_t a原创 2016-11-25 23:30:32 · 640 阅读 · 0 评论 -
中国剩余定理 Chinese remainder theorem(CRT)
中国剩余定理又称孙子定理, 主要是为了解线同余方程组x ≡ a1 ( mod m1 )x ≡ a2 ( modm2 )x ≡ a3 ( modm3 ) .........x ≡ an ( modmn )成立条件是m1,m2, ... ,mn 两两互质, 则对任意的整数:a1,a2, ... ,an,方程组S 有解 并且可以原创 2016-11-26 14:32:34 · 2399 阅读 · 0 评论 -
快速傅立叶 哈尔滨理工ACM程序设计全国邀请赛(网络同步赛) D. Pairs
PairsDescriptionGiven N integers,count the number of pairs of integers whose sum is less than K. And we have Mqueries. InputThe first behavioris an integer T (1 The next M lines,ea原创 2016-12-08 01:49:53 · 987 阅读 · 0 评论 -
日期类模板 , 该日期是第几天,第几天的日期,两个日期的差 ,一个日期的n天之后的日期...
http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=2315http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=10498以上是验证模板的题目/* * 模板有风险,使用需谨慎 , * 在获取某年的天数时,可以打原创 2016-12-10 20:27:43 · 581 阅读 · 0 评论 -
哈理工第六届程序设计团队赛 G ox
http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=2320problem G. OXTimeLimit: 1000ms Memory Limit: 100000kDescriptionKim喜欢玩井字棋。但是他从来都没有赢过:)Kim非常好奇井字棋是否有一个必胜的策略。给定一个原创 2016-12-10 18:46:37 · 488 阅读 · 0 评论 -
哈理工第六届程序设计团队赛 E Mod
http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=2318problem E . ModTimeLimit: 1000ms Memory Limit: 100000kDescriptionKim刚刚学会C语言中的取模运算(mod)。他想要研究一下一个数字A模上一系列数后的结果是原创 2016-12-10 18:38:34 · 592 阅读 · 0 评论 -
矩阵快速幂 例题+模板
1.http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1752推 Xi= (a * Xi-1 + b) % c + 1 ,直接做公式,不晓得哪里错了,wr了n次,换矩阵快速幂,1a。构造矩阵为将左边的矩阵乘n-1次#include using namespace std;typedef long long llt;原创 2016-08-15 17:35:41 · 936 阅读 · 0 评论 -
图论 二分图 最大团
KindergartenDescriptionIn a kindergarten, there are a lot of kids. All girls of the kids know each other and all boys also know each other. In addition to that, some girls and boys know each o原创 2016-09-02 12:01:24 · 1613 阅读 · 0 评论 -
后缀数组 spoj LCS - Longest Common Substring
1.LCSLCS - Longest Common SubstringA string is finite sequence of characters over a non-empty finite set Σ. In this problem, Σ is the set of lowercase letters. Substring, also called f原创 2016-08-31 21:00:15 · 481 阅读 · 0 评论 -
tyvj 1286 & hunnu 11296 校门外的树(2) 线段树或sort
P1286 校门外的树2时间: 1000ms / 空间: 131072KiB / Java类名: Main描述某校大门外长度为L的马路上有一排树,每两棵相邻的树之间的间隔都是1米。我们可以把马路看成一个数轴,马路的一端在数轴0的位置,另一端在L的位置;数轴上的每个整数点,即0,1,2,……,L,都种有一棵树。由于马路上有一些区域要用来建地铁。这些区域用它们在数轴原创 2016-08-03 21:06:13 · 327 阅读 · 0 评论 -
容斥例程 hdu 4135 Co-prime
#include #include #include #include #define INF ((1<<31)-1)using namespace std;typedef long long llt;int Factor[100000];int fi = 0;///计算质因子void sieve( int n ){ fi = 0; for (int i = 2原创 2016-08-03 18:48:07 · 216 阅读 · 0 评论 -
图论 最大流 Dinic
#include using namespace std;typedef int weight_t;const int SIZE_E = //500;const int SIZE_V = //205;int Start,End;struct edge_t{ int node; weight_t c; edge_t *next; edge_t *redg原创 2016-07-29 22:50:50 · 346 阅读 · 0 评论 -
sg函数 hdu 1729 Stone Game
题目大意:(取石子游戏)有n个箱子,体积为Si,当前箱子里的石子数为Ci。两个人轮流往箱子里放石子,而且每一次放是数量都有限制,不能超过当前箱子内石子数的平方。例如箱子里有3颗石子,那么下一个人就可以放1~9颗石子,直到箱子被装满。当有一方放不下石子时游戏结束,最后放不下石子的人输。首先空间为20的时候,ci == 20 sg = 0; ci == 19 sg = 1;原创 2016-07-28 10:58:15 · 153 阅读 · 0 评论 -
后缀数组 poj 3261
#include #include #include int const SIZE = 1001000;//分隔符,多串连接时需要用到,第0个为结束符,肯定用到char const DELIMETER[] = {'#'};int const DELIMETER_CNT = 1;//字母表的字母个数int const ALPHA_SIZE = DELIMETER_CNT + 26;原创 2016-07-29 19:49:06 · 250 阅读 · 0 评论 -
sg函数 poj 2960 S-Nim
#include #include #include #include using namespace std;int S[110];int S_len = 0;int sg[10050] = {0};bool flag[10050] = {0};int DFS(int state){ if ( sg[state] != INT_MIN) return sg[stat原创 2016-07-27 21:47:59 · 287 阅读 · 0 评论 -
spfa hdu 2066 一个人的旅行
/*c++ 62ms *g++ 78ms *spfa+暴力 */#include #define MEM(a,x) memset(a , x , sizeof(a))using namespace std;typedef int weight_t;const int SIZE_E = 1000000;const int SIZE_V = 1050;struct edge_t{原创 2016-07-27 10:36:53 · 359 阅读 · 0 评论 -
sg函数 hdu 1404 Digital Deletions
题目大意;给一个字符串,长度6以内,由0~9组成,有两个操作,每次进行一个, 把任意位上的非0的数变成一个比他小的数,例如1256 ,对5操作,把5变成 0,1,2,3,4,中任意一个,如果该位为0,则删除该位及后面所有位.sg 暴力dfs#include #include #include #include using namespace std;const原创 2016-07-25 23:21:21 · 350 阅读 · 0 评论 -
SG函数 Alice and Bob
题目大意是给定n的石子堆,每次只能从一个堆中取石子,每次取得石子不能少于该堆的一半,为先手能不能赢方法一 暴力DFS:直接爆搜sg#include #include #include #include #define MEM(a,x) memset(a,x,sizeof(a))using namespace std;int gcd(int a,int b){ re原创 2016-07-25 14:40:30 · 306 阅读 · 0 评论 -
后缀数组 poj 1743 Musical Theme(不重叠最大重复序列)
#include #include #include #include #include #define UP(i,x,y) for(int i=x;i<=y;i++)using namespace std;int gcd(int a,int b){ return b==0?a:gcd(b,a%b); }typedef long long llt ;//cout.sync_原创 2016-07-31 00:08:18 · 330 阅读 · 0 评论 -
spfa+枚举 hdu 3768 Shopping
题意不难理解,n个点组成的m条路,任选s个点,问s个点走一圈的最小路程,先spfa求出s个点相互直接的最短路程,然后DFS一下就行了。#include #include #include #include using namespace std;typedef int weight_t;const int SIZE_E = 200050;const int SIZE_V = 1原创 2016-08-01 15:09:45 · 308 阅读 · 0 评论 -
hunnu 10682 Invitation Cards
#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include原创 2016-07-24 12:28:09 · 266 阅读 · 0 评论 -
后缀数组 CSU - 1598 最长公共前缀
1598: 最长公共前缀Time Limit: 1 Sec Memory Limit: 128 MBDescription给定两个字符串s和t,现有一个扫描器,从s的最左边开始向右扫描,每次扫描到一个t就把这一段删除,输出能发现t的个数。Input第一行包含一个整数T(T每组数据第一行包含一个字符串s,第二行一个字符串t,字符串原创 2016-08-31 22:08:16 · 404 阅读 · 0 评论 -
二分匹配 hdu 1045 Fire Net
题意:给定一个最大4*4的方形地图,里面有墙(X)和空地(.)。在每个空地上可以放大炮,但两个大炮如果在同一行或同一列并且之间没有墙阻隔的话,会互相攻击,所以不能同时存在。问最多能放多少个大炮。刚开始看完全想不到是二分匹配,赶紧dfs肯定能做,数据范围小,不一定超时,参考了一下discuss,看到有二分匹配的,也就参考题解想了想这题首先要缩点,把竖列y连续的空地,给一样的数字,从1原创 2016-08-09 18:33:54 · 370 阅读 · 0 评论 -
csu 1105 NBUT 1108 打怪升级
打怪升级Description对于多数RPG游戏来说,除了剧情就是打怪升级。本题的任务是用最短的时间取得所有战斗的胜利。这些战斗必须按照特定的顺序进行,每打赢一场,都可能会获得一些补药,用来提升力量。本题只有两种补药:“加1药”和“乘2药”,分别让你的力量值加1和乘以2。战斗时间取决于你的力量。每场战斗可以用6个参数描述:p1, p2, t1, t2, w1, w2原创 2016-08-19 00:13:50 · 643 阅读 · 0 评论