08 2018 档案
摘要:Vasya has decided to build a zip-line on trees of a nearby forest. He wants the line to be as long as possible but he doesn't remember exactly the hei
阅读全文
摘要:Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by sw
阅读全文
摘要:Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting. Suppose the graph G
阅读全文
摘要:Long time ago, there was a great kingdom and it was being ruled by The Great Arya and Pari The Great. These two had some problems about the numbers th
阅读全文
摘要:Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but the
阅读全文
摘要:For a connected undirected weighted graph G, MST (minimum spanning tree) is a subgraph of G that contains all of G's vertices, is a tree, and sum of i
阅读全文
摘要:A point belongs to a triangle if it lies inside the triangle or on one of its sides. Two triangles are disjoint if there is no point on the plane that
阅读全文
摘要:Dima the hamster enjoys nibbling different things: cages, sticks, bad problemsetters and even trees! Recently he found a binary search tree and instin
阅读全文
摘要:One day Natalia was walking in the woods when she met a little mushroom gnome. The gnome told her the following story: Everybody knows that the mushro
阅读全文
摘要:I guess there's not much point in reminding you that Nvodsk winters aren't exactly hot. That increased the popularity of the public transport dramatic
阅读全文
摘要:Sherlock Holmes found a mysterious correspondence of two VIPs and made up his mind to read it. But there is a problem! The correspondence turned out t
阅读全文
摘要:You have been offered a job in a company developing a large social network. Your first task is connected with searching profiles that most probably be
阅读全文
摘要:题意:给定N点,M边,求添加最少的边使之变为连通图的方案数。 思路:注意题目给出的M边可能带环,即最后生成的不一定是一棵树。但是影响不大。根据矩阵树定理,我们知道生成树的数量=N^(N-2),即点数^(连通数-2)。 此题把已经连通的看成一个整体,就可以得到数量为N^(cnt-2),然后考虑连通块内
阅读全文
摘要:Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things were different. In Ancient Berland arenas in circu
阅读全文
摘要:De Prezer loves rectangles.He has a n × m rectangle which there is a number in each of its cells. We show the number in the j - th column of the i - t
阅读全文
摘要:题意:给定字符串char[],以及Q个操作,操作有三种: 1:pos,chr:把pos位置的字符改为chr 2:pos:问以pos为中心的回文串长度为多长。 3:pos:问以pos,pos+1为中心的回文串长度为多长。 思路:用hash表示一段字符串或者连续子串。我们用BIT记录hash前缀和,那么
阅读全文
摘要:题意:给定N点M边的有向图,每条边有距离和颜色,一条有效路径上不能有相邻的边颜色相同。现在给定起点S,多次讯问S到点X的最短有效距离。 TLE思路:用二维状态dis(u,c)表示起点到u,最后一条边的颜色是c的最短距离,用map解决了二维空间不足的问题。但是T第151个点。所以需要优化,标解的优化是
阅读全文
摘要:题意:给定N的棒棒,K种颜色,每个棒棒的两端可以涂色。现在已知所有的线段要么有一端涂色,要么两端都没有涂色,现在要求把所有的没涂色的部分涂色,使得我们可以把涂色后的棒棒分为N/K组,每组的涂色情况相同。 思路:把没有颜色的棒子,看成一端涂色为0,那么现在每个线段都有一端涂色。我们按照数量来排序,然后
阅读全文
摘要:题意:一个顶点数为N的生成树,对于每个点i,我们按照与i的距离给出顺序,即dis i 1<=dis i 2<=dis i 3<=...,现在让你输出N-1条边,即还原这棵树。 思路:首先应该得到距离为1的点对,那些肯定是树边,然后这样得到的树边可能<N-1,后面不容易判定哪些是树边。搜索什么的都不好
阅读全文
摘要:Nikita likes tasks on order statistics, for example, he can easily find the kk-th number in increasing order on a segment of an array. But now Nikita
阅读全文
摘要:After the war, the supersonic rocket became the most common public transportation. Each supersonic rocket consists of two "engines". Each engine is a
阅读全文
摘要:题意:给定平面上N个点,问是否存在三角形,其面积为S。 思路:选择Y轴,枚举这个Y轴,面积大小只与|y-Y|有关,然后二分,具体的可以先去做BZOJ3707。 具体的: 1,先对点排序,X坐标为第一关键字,Y坐标为第二关键字,从小到大排序。 2,得到C(N,2)条直线,按照它们的斜率为关键字(叉积排
阅读全文
摘要:Mrs. Smith is trying to contact her husband, John Smith, but she forgot the secret phone number! The only thing Mrs. Smith remembered was that any per
阅读全文
摘要:Notice: unusual memory limit! After the war, destroyed cities in the neutral zone were restored. And children went back to school. The war changed the
阅读全文
摘要:题意:给定一个N,让你把它拆成若干个只含素因子2和3的数之和,且两两之间没有倍数关系,比如10=4+6。 思路:即是2因子的幂递增,3因子的幂递减;或者反之。 对于当前N,我们拆分出的数为num=2^x*3^y;满足2^x|N,而且y最大,然后把继续拆分N-num。不难推出,N-num是个偶数,且至
阅读全文
摘要:题意: 一个宽度为N的网格图,i上有h[i]高的方块。现在你有W个方块,问怎么放使得最终的最高点最高。 当一个格子的下方,左下方和右下方都有方块那么久可以把方块放到这个格子上。最左端和最右端不能放方块。 (N<=100000,W<=1018,h[i]<=109) 思路:显然是二分,对于二分的高度Mi
阅读全文
摘要:???
阅读全文
摘要:题意:现在有函数,每一项Xi=(A*X(i-1)+B)%C。现在给定N个函数以及K:X0,A,B,C。然你再每个函数选择一个数,使得其和最大,而且不被K整除。 X0,A,B,C<=1e3 ;K<=1e9 思路:因为C比较小,我们可以找到循环节(不一定是从0开始就循环了,所以用vis判定是否出现过)。
阅读全文
摘要:题意:给定长度为N的01串,现在让你猜这个串,猜的次数要不超过N+500次。 每次你猜一个串,系统会返回N/2,或N,或0。当且当有N/2个位置猜对,N个位置猜对,其他。 思路:因为信息不多,没有关联性,所以前期只有瞎猜,直到猜到一个N/2,(如果是N也ok)。猜到N/2之后,我们从这个N/2串考虑
阅读全文
摘要:题意:给定一个N点M边的有向图,叫你加最多K条边,使得最小拓扑序最大. 思路:不是那么简单的题. 参照了别人的代码, 最后想通了. 贪心原则: 用两个单调队列维护, 第一个序列S1单增, 表示当前入度为0的点 ; 第二个序列S2单减,表示需要加边的点. 如果S1的最大值大于S2的最大值,则对其加边.
阅读全文
摘要:题意: 现在有1,2,3...N这N个站, 给定限定时间Limt, N-1种票的价格, 分别对应一个最远距离, 叫你选择一种票, 满足可以在规定时间到达N站台,而且价格最低 思路: 如果买距离为L的票可以在规定时间到,那么距离>L的票也一定能到. 我们只需要二分出这个下界 L,然后在>=L里选择一个
阅读全文
摘要:题意:给定X,Y,分别表示由'.'和'@'组成的连通块的个数。 思路:假如X<Y,我们用两部分来构造这个结果,第一部分由一个'.'连通块和Y-(X-1)割'@'连通块组成,第二个部分由X-1个'.'连通块和X-1个'@'连通块组成. 其他情况同理.
阅读全文
摘要:题意:给定一个凸包,现在让你连接凸包上两点,把凸包变为两个多边形,满足两个多边形的面积都是整数。 思路:我们知道整点的三角形面积S=叉积/2,则S要么是整数,要么是整数+0.5。那么多边形有多个三角形组成=So01+So12+So23+...(o是原点),也有这样的性质。因此,我们现在在算面积的时候
阅读全文
摘要:题意:现在有一棵树,1号节点是水源,叶子节点是村庄,现在有些怪兽会占领一些村庄(即只占领叶子节点),现在要割去一些边,使得怪兽到不了水源。给出怪兽占领和离开的情况,现在要割每次回答最小的割,使得怪兽不与1号节点有联系,而且满足被阻隔的村庄最少。输出最小割与组少的被误伤的村庄。 思路:把与一号节点相邻
阅读全文
摘要:题意:N个人,每个人有a属性和b属性,如果一个人的a或者b大于另外一个人,我们说这个人可以打败那个人。且这种关系可以传递。对于每个人,输出他可以打败多少人。(保证每个a不相同,保证每个b不相同。 思路:对于a关系,我们按重小到大连边,b同理。然后每个点能到的点就是可以打败的点。即是缩点后乱搞。 (此
阅读全文
摘要:题意:给定当前汉诺塔的状态,问还有多少步走完,不合法输出“No”。 思路:显然可以一层一层试探下去的。我们设三个柱子为“起始”,“中转”,“终点”,当前状态的最大的盘子不可能在中转站处;如果在起始站,我们需要把其他的移到中转站,然后把最大移到终点。如果在终点站,我们需要把其他的从中转站移到终点站。
阅读全文
摘要:题意:一个环状数组,给定可以删去一个数,代价的相邻两个数的gcd,求最小代价。 思路:区间DP即可,dp[i][j]表示[i,j]区间只剩下i和j时的最小代价,那么dp[i][j]=min dp[i][k]+dp[k][j]+gcd(a[[i],a[j])。带上注意不能加倍做,以为常数会乘8,TLE
阅读全文
摘要:题意:给定几个圆,求最短的围合,把这几个包围起来,而且到圆的距离都不小于10. 思路:把每个圆的半径+10,边等分5000份,然后求凸包即可。
阅读全文
摘要:手抄码板大法。
阅读全文
摘要:A string a of length m is called antipalindromic iff m is even, and for each i (1 ≤ i ≤ m) ai ≠ am - i + 1. Ivan has a string s consisting of n lowerc
阅读全文