12 2012 档案
摘要:问题:模线性同余方程组: x = a1 ( mod n1 ) x = a2 ( mod n2 ) .... x = ak ( mod nk )给定 A ( a1, a2 , ... , ak ) , N ( n1, n2, ..., nk ) 求 X 。通常分为两种 一, ( Ni, Nj ) 之间两两互质 二, ( Ni, Nj ) 之间不都互质一 ( Ni, Nj ) 之间两两互质 定理( 见算法导论 P874 ): 如果 n1, n2 , ... , nk 两两互质, n = n1*n2*..*nk ,则对任意整数 a1,a2,a3..,ak , 方程组 x =...
阅读全文
摘要:没看到题目上说 仅一个循环因子.. 现在我还是没看到.....WA了好久, 一直用 置换群分解循环因子后,对每一个循环因子 其 阶数即为循环节. 之后无限WA..找了好久.才发现. 这里的置换, 每一次 double shuffer 后. 其循环因子顺序已经改变了. 我们使用循环因子的顺序是相对于最初的情况而言.所以这里不能够用循环因子来做.模拟其置换过程,找出其 置换循环 D, 对于置换X经过S次置换后得到Y, 则 Y再经过 D-S%D 次置换后又回到 X.View Code #include<stdio.h>#include<stdlib.h>#include<
阅读全文
摘要:对于每个 Block 求出其 循环因子,我这里是用 Vector 动态数组,省事 循环因子顾名思义就是置换会出现循环. 这样把时间复杂度降下来. 因为串总长才 200 , 分别处理每一个循环因子. 可以选择一个一个移动模拟, 也可以一次到位. 我都试了下,都是700+Ms. 虽然区别不大, 估计是数据问题吧. 数据量大了肯定影响很大.View Code #include<stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>#include<iostream>#i
阅读全文
摘要:总共共10^5个数,取值在10^6之内 离散化后与下标形成映射,转换成置换群 然后就可以形成: 有 n = 10^5 个位置, 每个位置有一头编号为 a[i] (取值范围为[1,n] ) 的牛, 其愤怒值为 dep[ a[i] ] 对于置换群求出其循环因子后. 因为置换的权值花费为 dep[i], dep[j] 所以我们取最小的 dep, 例如循环因子 ( 1 , 4, 7, 8 ) 需要三次置换 , 我们可以取最小的 1, 其愤怒值为 dep[1] ( 我们按权值递增离散化过) 所以三次置换分别为 ( 1, 4 ) ( 1, 7 ) ( 1, 8 ) 则三次花费为 ( de...
阅读全文
摘要:题目来源 HDU 2008-10 Programming ContestIDOriginTitleProblem AHDU 2520我是菜鸟,我怕谁Problem BHDU 2521反素数Problem CHDU 2522A simple problemProblem DHDU 2523SORT AGAINProblem EHDU 2524矩形A + BProblem FHDU 2525Clone WarsProblem GHDU 2526浪漫手机Problem HHDU 2527Safe Or UnsafeProblem A 仔细读题, 这个不是匀变速运动, 每一秒初,速度直接改变. 化简.
阅读全文
摘要:题目大意: 对于方程 输入 k ( 0 <= k <= 20 ) 输出 解题思路: 由数学 伯努利数 公式: 带入通分化简就可以了,不过要注意,分母为正...( WA了一小时错在了这里 ) 伯努利数是18世纪瑞士数学家雅各布·伯努利引入的一个数。 设伯努利数为B(n),它的定义为: t/(e^t-1)=∑[B(n)*(t^n)/(n!)](n:0->;∞) 这里|t|<2。由计算知: B(0)=1,B⑴=-1/2, B⑵=1/6,B⑶=0, B⑷=-1/30,B⑸=0, B⑹=1/42,B⑺=0, B⑻=-1/30,B⑼=0), B⑽=5/66,B⑾=0, .
阅读全文
摘要:题目大意: 使用三种颜色珠子串成 一个n颗珠子的项链,项链旋转和翻转相同的视为同样方案,问有多少不同方案数 对于 群论中置换群的计算公式我们有 BurnSide 和 Polya 前者是找所有置换群,后者是找置换群循环因子,其两者公式也相差不远,因为 Polya计数 比较方便,所以通常使用 Polya公式 其中 ei 为第 i 个置换,其循环因子数量 对于 n 角/边对称图形, 其包括 旋转 和 反射 旋转顶点数量为 ( 0, 1, 2 ... n-1 ) : 循环因子数量: Gcd( n, i ) 反射对于 偶数n 时,分为 n/2个顶点反射 与 n/2个边...
阅读全文
摘要:题目大意: 给出递推公式,求 % 1e9+7 看大神们的思路:除1外,奇数全为0,对于偶数2k,答案为(-1)^k*fact[2k]*catalan(k+1)。p[i]表示i的阶乘。表示弱菜依旧无法理解哪里看出来的规律,哪怕是 catalan(n) 为 阶乘倍数的关系知道我也没弄出来...求大神普渡~~~AC代码:View Code #include<stdio.h>#include<stdlib.h>#include<string.h>#include<algorithm>using namespace std;typedef long lon
阅读全文
摘要:解题思路: 对于置换群 分解其循环因子 对于 需要对换一次,对于 需要对换两次, 所以当前置换群最少对换次数为三 对于 本题, 我们先 求出其 循环因子后,再从小到大 进行贪心即可解题代码:View Code #include<stdio.h>#include<string.h>#include<queue>#include<iostream>#include<algorithm>using namespace std;const int N = 100010;int a[N], b[N], n , k;bool vis[N];int
阅读全文
摘要:友情提示: 注意先给 博客添加 JS支持功能后,在页首添加相关代码才可显示。 需要手动复制HTML 可直接复制生成图片: 在线画图链接 C++ 资料库 在此做个标记方便使用~~~
阅读全文
摘要:刘雅琼PPT讲解链接:http://wenku.baidu.com/view/8e9ebefb0242a8956bece4b3.html扩展KMP: 给出模板串A和子串B,长度分别为lenA和lenB,要求在线性时间内,对于每个A[i](0<=i<lenA), 求出A[i..lenA-1]与B的最长公共前缀长度,记为ex[i](或者说,ex[i]为满足A[i..i+z-1]==B[0..z-1]的最大的z值)。 扩展KMP可以用来解决很多字符串问题,如求一个字符串的最长回文子串和最长重复子串。【算法】 设next[i]为满足B[i..i+z-1]==B[0..z...
阅读全文
摘要:例题是 POJ 1061 青蛙的约会 题目大意是,一个周长为L的圆, A、B两只青蛙,分别位于 x 、y 处,每次分别能跳跃 m 、n ,问最少多少次能够相遇,如若不能输出 “ Impossible” 此题其实就是扩展欧几里德算法-求解不定方程,线性同余方程。 设过 k1 步后两青蛙相遇,则必满足以下等式: ( x + m*k1 ) - ( y + n*k1 ) = k2*L ( k2 =0 , 1 , 2....) //这里的k2: 存在一个整数k2, 使其满足上式 稍微变一下形得: ( m - n )*k1 - k2*L= y - x 令 a = m - ...
阅读全文
摘要:首先贴上 NBU 嘟嘟洒水车 大神的解题思路:http://www.acdream.net/problem.php?id=1042题目大意:(把物种和分类都看成节点。)有一颗未知树,一人每次询问两个叶子节点,另一个人回答其lca,判回答之间是否有矛盾。解法:将每条陈述按照lca的深度由深到浅排序,然后扫一遍开始并查集。比如说现在搞到这条陈述:x y a,那么查到xy的根节点 x_father y_father。由于是按照a的深度由深到浅搞的,所以a必然是x_father和y_father的祖先。那就分类讨论这样是否可能:一、a是x(y)_father之一:1、x_father和y_father
阅读全文
摘要:解题思路: 对于每一个节点有三个值来唯一标志( L, cur, R ) 分别表示 左上根, 本身, 右上根 对于两种走法: 向左走, 左上根不变, 右上根更新 表达式为: L = L, R = ( L + R ) 向右走, 右上根不变, 左上根更新 表达式为: L = ( L + R ), R = R 当向走或向右走 N 步时, 可得 N*L + R 或 L + N*R 数据过大,需使用64int, 使用按位模拟乘法避免溢出解题代码:View Code #include<stdio.h>const int N = 10000007;const int mod = 1...
阅读全文
摘要:先给出 Lyush 大神的部分解题思路HDU-4255 A Famous Grid BFS 知识点:素数筛选+模拟 难度:中等Source Fudan Local Programming Contest 2012思路:得到两个表,一个素数表,一个是矩阵表,然后搜索即可,一个要注意的地方是要把矩阵打的稍微大一点,因为可能要走到外面去。HDU-4386 Quadrilateral知识点:海伦公式推广,数学难度:中等Source 2012 Multi-University Training Contest 9思路:这题就是一个结论了,当四边形为圆的内接四边形,面积最大。设四边长为abcd,半周长为p
阅读全文
摘要:本次题目皆来源于 HDUOJ 题目编号:IDOriginTitleProblem AHDU 4475Downward pathsProblem BHDU 4476Cut the ropeProblem CHDU 1576A/BProblem DHDU 1060Leftmost DigitProblem EHDU 1066Last non-zero Digit in N! 5个题目都属于思维题,且都没有复杂的编码,但是对逻辑思维转换还是有一定的要求. 笔者希望大家能够多细心思考,注重严谨的逻辑推导。 虽然题目不难也不易,但是Acm的队员们还是相当不错,二年级的唐仕首当其冲踩过了A,C两题...
阅读全文
摘要:题目大意和思路同上题类似, 本题特殊点为其需要将多组满足要求的结果按递增全部输出。解题代码: View Code #include<stdio.h>#include<string.h>#include<stdlib.h>using namespace std;#define MAX(a,b) (a)>(b)?(a):(b)#define MIN(a,b) (a)<(b)?(a):(b)const int N = 50010;int M[N], n;int head[N], idx;struct node{ int max, sum;}D[N];s
阅读全文
摘要:解题思路: 树重心,将其与其最大子树连接的边,删除后,划分出的两个子树节点数量最大的中的最小. 题目其实是树的重心的一点变异。 树的重心是 树中所有节点的字节点数量最大中的最小的节点 O(n) 求出每个点的的子节点的最大值以及其字节点总个数,然后在线性比较下就可以求出重心了, 此题要注意, 这里要求的是 所有的(节点的子节点数量的最大值)中最小的. 解题代码: View Code #include<stdio.h>#include<string.h>#include<stdlib.h>using namespace std;#define MAX(a,b)
阅读全文
摘要:关于分治算法在树上的应用详情请查看09年QZC国家集训队论文。题目大意: 树含N个点,点之间有权值,求两点间权值和小于等于K的点对数量( N <= 10000 )解题思路:对于以rt为根节点的树,其树上两点间一条路径只有两种情况,分别为过根节点,不过根节点。 这样,启发了我们使用分治的思想来解决此题。 若不过根节点,则通过递归处理,其实也可理解为过根节点,但过了根的那部分为0.可简化代码 若过根节点, 则 dist(i)+dist(j) <= K 且 father(i) != father(j) 其中哦功能 dist(i) 为 子树上节点到根节点rt的距离, fath...
阅读全文
摘要:du熊填数字Time Limit:3000/2000 MS (C/Others) Memory Limit: 65536/32768 K (C/Others)本次组委会推荐使用C、C++Problem Description du熊这几天使劲的往一个n 行n列的矩阵填0和1这两个数字,n为偶数,而且矩阵由里向外分成了n / 2层。比如n = 6时,矩阵的分层如下: du熊填数时有一个要求:不能存在两个相邻的1,且位于不同的层(这里的相邻指两格子共用一条线)。 请你帮du熊计算一下有多少种填法。Input 输入包含多组测试数据,每组数据包含一个偶数n (2 <= n <= 500)。
阅读全文
摘要:du熊学斐波那契ITime Limit : 2000/1000ms (C/Other)Memory Limit : 65535/32768K (C/Other)本次组委会推荐使用C、C++Problem Descriptiondu熊对数学一直都非常感兴趣。最近在学习斐波那契数列的它,向你展示了一个数字串,它称之为“斐波那契”串:11235813471123581347112358........聪明的你当然一眼就看出了这个串是这么构造的:1.先写下两位在0~9范围内的数字a, b,构成串ab;2.取串最后的两位数字相加,将和写在串的最后面。上面du熊向你展示的串就是取a = b = 1构造出来
阅读全文
摘要:C. Anagramtime limit per test1 secondmemory limit per test256 megabytesStringxis ananagramof stringy, if we can rearrange the letters in stringxand get exact stringy. For example, strings "DOG" and "GOD" are anagrams, so are strings "BABA" and "AABB", but stri
阅读全文
摘要:题目大意: 有K个挤奶器,C头奶牛,每个挤奶器最多能给M头奶牛挤奶。求使C头奶牛头奶牛需要走的路程的最大路程最小。解题思路: 使用Floy预先求出任意两点间最短距离,然后二分枚举最大距离. 构图方案: 源点与奶牛连边,容量为1, 挤奶器与汇点连边,容量为M, 奶牛与挤奶器连边 (注意,这里只有单项边) 还要注意的是,因为预先求过最短路,初始化的时候对于0的边,赋值的无穷大不要设的太大,不然会溢出.参考代码: SAP(shortest augment path) 间隙优化, AC时间 110ms View Code #include<stdio.h>#include<stdli
阅读全文
摘要:解题思路: 源点为1,汇点为N, 直接求最大流就好View Code #include<stdio.h>#include<string.h>#include<string.h>#define MIN(a,b) (a)<(b)?(a):(b)const int inf = ~0u>>1;const int MAXN = 210;int n, m, S, T, N;int head[MAXN], idx, h[MAXN], vh[MAXN];struct Edge{ int v, f, nxt; }edge[MAXN<<4];voi
阅读全文
摘要:PIGSTime Limit:1000MSMemory Limit:10000KTotal Submissions:12924Accepted:5721DescriptionMirko works on a pig farm that consists of M locked pig-houses and Mirko can't unlock any pighouse because he doesn't have the keys. Customers come to the farm one after another. Each of them has keys to s
阅读全文
摘要:1017: Fast TransportationTime Limit:10 SecMemory Limit:128 MBSubmit:72Solved:11DescriptionI’m working for a huge transportation company, and this month we get a job that deliver K important medicinal machines from city S to city T. Since the machines is so large that for each machine we should use a
阅读全文
摘要:B. Jury Sizetime limit per test1 secondmemory limit per test256 megabytesinputinput.txtoutputoutput.txtIn 2013, the writers of Berland State University should prepare problems fornOlympiads. We will assume that the Olympiads are numbered with consecutive integers from 1 ton. For each Olympiad we kno
阅读全文
摘要:A. Cards with Numberstime limit per test1 secondmemory limit per test256 megabytesinputinput.txtoutputoutput.txtPetya has got2ncards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from1to2n. We'll denote the number th
阅读全文
摘要:Power NetworkTime Limit:2000MSMemory Limit:32768KTotal Submissions:19147Accepted:10099DescriptionA power network consists of nodes (power stations, consumers and dispatchers) connected by power transport lines. A node u may be supplied with an amount s(u) >= 0 of power, may produce an amount 0 &l
阅读全文
摘要:C. Text Editortime limit per test1 secondmemory limit per test256 megabytesVasya is pressing the keys on the keyboard reluctantly, squeezing out his ideas on the classical epos depicted in Homer's Odysseus... How can he explain to his literature teacher that he isn't going to become a writer
阅读全文
摘要:B. Physics Practicaltime limit per test1 secondmemory limit per test256 megabytesOne day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much asnmeasurements, and recorded the results in the notebook. After that he w
阅读全文
摘要:A. Boys and Girlstime limit per test1 secondmemory limit per test256 megabytesThere arenboys andmgirls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers
阅读全文
摘要:1019: PalindromeTime Limit:1 SecMemory Limit:128 MBDescriptionNow we have a long long string, and we will have two kinds of operation on it.C i y: change the ith letter to y;Q i j: check whether the substring from ith letter to jth letter is a palindrome.InputThere are multiple test cases.The first
阅读全文
摘要:1014: Dice Dice DiceTime Limit:10 SecMemory Limit:128 MBDescriptionThere are 1111 ways in which five 6-sided dice (sides numbered 1 to 6) can be rolled so that the top three numbers sum to 15. Some examples are:D1,D2,D3,D4,D5 = 4,3,6,3,5D1,D2,D3,D4,D5 = 4,3,3,5,6D1,D2,D3,D4,D5 = 3,3,3,6,6D1,D2,D3,D4
阅读全文