这是CF Goodbye 2015 的D题,当时我想了一个n^3的dp算法,肯定不能过,然后听到学长后缀数组的n^2log(n)写法,仰慕 最后打完比赛看到了t神的n^2写法,简直膜拜,直接省去了后缀数组,而且用一个sum由n^3变成了n^2,唉,经验无与伦比.Orz.. 下面的代码就是我照着写的: #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #inclu…
f[i = 以i结尾][j = 长度为j] = 方案数. f[i][j] = sum{ f[i-j][k] , k < j || (k == j && s(i-j+1,j) > s(i-2*j+1,j) ) } 转移为O(N^3)需要优化, 对于k < j,递推g[i][j] = sum(f[i][k], k <= j). 对于k == j,有O(N^2)个后缀,可以用二维数组lcp[i][j]递推i和j开头的最长公共前缀. (后缀数组倍增大概也可以做的,用memc…
time limit per test2.5 seconds memory limit per test512 megabytes inputstandard input outputstandard output Limak is a little polar bear. In the snow he found a scroll with the ancient prophecy. Limak doesn't know any ancient languages and thus is un…
D. New Year and Ancient Prophecy 题目连接: http://www.codeforces.com/contest/611/problem/C Description Limak is a little polar bear. In the snow he found a scroll with the ancient prophecy. Limak doesn't know any ancient languages and thus is unable to u…
D. New Year and Ancient Prophecy time limit per test 2.5 seconds memory limit per test 512 megabytes input standard input output standard output Limak is a little polar bear. In the snow he found a scroll with the ancient prophecy. Limak doesn't know…
C. Ancient Berland Circus 题目连接: http://www.codeforces.com/contest/1/problem/C Description 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 circuses were s…
/* 题意:给一个长度不超过5000的字符串,每个字符都是0到9的数字. 要求将整个字符串划分成严格递增的几个数字,并且不允许前导零. 思路: 1.很开心得发现,当我在前i个区间以后再加一个区间的时候,转移 的条件只跟最后一个区间的数字大小有关,这决定这道题可以dp... 2.dp[i][j]代表前j个字符,最后划分的区间的第一个字符是第i个的答案数. 3.可知对于所有的dp[i][i...n]他们的答案都取决与dp[1...i-1][i-1]. 4.很容易想到对于同一个i,累加求得dp[i][…
[codeforces 260]B. Ancient Prophesy 试题描述 A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-". We'll say that some date is mentioned in the P…
B. Ancient Berland Hieroglyphs 题目连接: http://codeforces.com/problemset/problem/164/B Descriptionww.co Polycarpus enjoys studying Berland hieroglyphs. Once Polycarp got hold of two ancient Berland pictures, on each of which was drawn a circle of hierog…
Fafa and Ancient Mathematics 转换成树上问题dp一下. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #define PII pair<int, int> #define SZ…
260B - Ancient Prophesy 思路:字符串处理,把符合条件的答案放进map里,用string类中的substr()函数会简单一些,map中的值可以边加边记录答案,可以省略迭代器访问部分. 代码: #include<bits/stdc++.h> using namespace std; ; map<string,int>mp; string s; ]={,,,,,,,,,,,}; bool isOK(string s) { ]!=]!='-')return fals…
C. Ancient Berland Circus time limit per test 2 seconds memory limit per test 64 megabytes input standard input output standard output Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things were different.…
1C - Ancient Berland Circus 思路: 求出三角形外接圆: 然后找出三角形三条边在小数意义下的最大公约数; 然后n=pi*2/fgcd; 求出面积即可: 代码: #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define INF (1e9…
题目链接  Codeforces Round #465 (Div. 2) Problem E 题意  给定一个表达式,然后用$P$个加号和$M$个减号填充所有的问号(保证问号个数等于$P + M$) 求可以形成的表达式的最大值. 先把表达式转成一棵树,然后在树上DP. 题目保证了$min(P, M) <= 100$, 为了提高效率,我们选择用少的运算符号作为DP的第二维. 对$P$和$M$的大小关系进行分类讨论. 当$P < M$时, 设$f[i][j]$表示$i$代表的子树里面填$j$个加号…
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 circuses were shaped as a regular (equiangular) polygon, the size and the number of angles could vary fro…
题目链接:https://codeforces.com/contest/1362/problem/A 题意 有一个正整数 $a$,可选择的操作如下: $a \times 2$ $a \times 4$ $a \times 8$ $a\ /\ 2$,如果 $2$ 整除 $a$ $a\ /\ 4$,如果 $4$ 整除 $a$ $a\ /\ 8$,如果 $8$ 整除 $a$ 问能否由 $a$ 得到正整数 $b$,以及最少的操作次数. 题解 贪心模拟即可. 代码 #include <bits/stdc+…
题目链接:A.Johnny and Ancient Computer 题意: 给你两个数a,b.问你可不可以通过左移位运算或者右移位运算使得它们两个相等.可以的话输出操作次数,不可以输出-1 一次操作可以最多左移3次或者右移3次 题解: 首先找寻一下这两个数的二进制形式下最右边那个1在什么位置.然后看一下它们的差距是多少(设为x) 那么就让a,b中小的那个数左移x位.之后判断一下它们两个相等不相等就可以了 代码: 1 #include<stdio.h> 2 #include<algori…
传送门 题意 给出一正多边形三顶点的坐标,求此正多边形的面积最小值. 分析 为了叙述方便,定义正多边形的单位圆心角u为正多边形的某条边对其外接圆的圆心角(即外接圆的某条弦所对的圆心角). (1)多边形的边数未知,但其外接圆是确定的.多边形的外接圆即三个顶点所构成三角形的外接圆.面积最小即边数最少,单位圆心角最大. (2)设三角形某两边所对的圆心角为a1, a2 (expressed in radians),则最大单位圆心角为 u= gcd(a1, a2, 2PI-a1-a2). 思路 (1)三点…
原文链接https://www.cnblogs.com/zhouzhendong/p/CF1045E.html 4K码量构造题,CF血腥残暴! 题解 首先,如果所有点颜色相同,那么直接连个菊花搞定. 然后我们建个凸包. 如果凸包上有大于2段颜色(就是至少四段),比如这样 那么必然无解. 否则就只有一段颜色或者两段颜色: 这里我们先不管这个,考虑一个三角形的构造. 考虑三角形三个顶点颜色不全相同的情况,例如: (两个白点的情况是等价的) 假如三角形区域内没有白点,那么直接全部连到其中一个黑点就好了…
题意:给定一个表达式,然后让你添加 n 个加号,m 个减号,使得表达式的值最大. 析:首先先要建立一个表达式树,这个应该很好建立,就不说了,dp[u][i][0] 表示 u 这个部分表达式,添加 i 个符号,使值最大,dp[u][i][1] 表示 u 个部分表达式,添加 i 个符号,使用值最小,这里添加的符号可能是加号,也可以是减号,就是最小的那个,因为题目说了min(n, m) <= 100,一开始我没看到,就 WA8 了.然后在状转移的时候,分成两类,一类是添加的是加号,那么 dp[u][i…
传送门 概率dp水题. 题意简述:给你数字表的大小和两个数列,数列中为0的数表示不确定,不为0的表示确定的,求第一个数列字典序比第二个数列大的概率. fif_ifi​表示第i ni~ ni n位第一个数列比第二个数列大的概率. 然后分是否为0的情况讨论一下就行了. 代码: #include<bits/stdc++.h> #define ri register int using namespace std; inline int read(){ int ans=0; char ch=getch…
题目链接 题意 给定两个\(n\)位的\(m\)进制数\(s1,s2\),所有出现的\(0\)均可等概率地被其他数字替换,求\(s1\gt s2\)的概率. 思路 从高位到低位,根据每一位上相应的\(0\)的个数进行 分类讨论. 计算每一位的时候加上这样一部分答案:比到该位恰能比出大小的情况数. 恰能比出大小意味着:高位全部相同,该位\(s1\gt s2\),低位随便怎么取. 因此,需对两个数目进行记录:1. 前面有多少位是两者皆0:2. 后面还有多少个0没有确定. 另:\(x\)关于\(mod…
Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Description Having unraveled the Berland Dictionary, the scientists managed to read the notes of the chroniclers of that time. For example, they learned how the chief of the…
A. Warrior and Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/594/problem/A Description In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this…
A. Theatre Square time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the ci…
题目链接: http://codeforces.com/problemset/problem/337/D D. Book of Evil time limit per test2 secondsmemory limit per test256 megabytes 问题描述 Paladin Manao caught the trail of the ancient Book of Evil in a swampy area. This area contains n settlements num…
D. Remainders Game 题目连接: http://www.codeforces.com/contest/688/problem/D Description Today Pari and Arya are playing a game called Remainders. Pari chooses two positive integer x and k, and tells Arya k but not x. Arya have to find the value . There…
C. Old Berland Language 题目连接: http://www.codeforces.com/contest/37/problem/C Description Berland scientists know that the Old Berland language had exactly n words. Those words had lengths of l1, l2, ..., ln letters. Every word consisted of two letter…
题目链接:http://codeforces.com/contest/975 A. Aramic script time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output In Aramic language words can only represent objects. Words in Aramic have special pro…
题目链接:http://codeforces.com/problemset/problem/215/B Description The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of r1 cm, inner radius of r2 cm, (0 < r2 < r1) made of metal wi…