A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six sub…
link:http://codeforces.com/problemset/problem/340/C 开始一点也没思路,赛后看别人写的代码那么短,可是不知道怎么推出来的啊! 后来明白了. 首先考虑第一个数字,就是和0想减的内个.那么剩下的n-1个数字有(n-1)!个排列方式.所以呢,在n!个式子里面,第一个位置的和就是:a1 * (n-1)! + a2 * (n-1)! + ...... + an * (n-1)!: 然后考虑其它位置:对于ai , aj . 并且相邻.那么剩下 n - 2 个…
题目链接:http://codeforces.com/problemset/problem/337/B 看到这个题目,觉得特别有意思,因为有熟悉的图片(看过的一部电影).接着让我很意外的是,在纸上比划了一下,凭着直觉,竟然一次AC,那个兴奋啊 !^_^ !  好啦,不说废话. 这个题目被分类为 math 和 matrices ,数学还好理解,matrices,应该是母函数吧(不好意思的说,还没系统地学到),姑且让我分类到数学里吧.题目的意思是,给出一个水平长度 : 垂直长度的比例分别为 a:b…
http://codeforces.com/problemset/problem/527/D 题意:给出一些点的xi和wi,当|xi−xj|≥wi+wj的时候,两点间存在一条边,找出一个最大的集合,集合中的点两两之间存在边 化开有 xi-xj>=wi+wj ==> wj+xj<=wi-xi xj-xi>=wi+wj ==> wi+wx<=wj-xj 发现本质相同,我们按x+w排序,从最小的往大的贪心连边,因为如果有一条边,那么比它小的也全部可以连到边. #include…
题目链接:https://codeforces.com/problemset/problem/706/C 题意: 给出 $n$ 个字符串,对于第 $i$ 个字符串,你可以选择花费 $c_i$ 来将它整个翻转. 要你尽量用最少的花费,使得 $n$ 个字符串按照字典序升序排序. 题解: $f[i][0,1]$ 表示前 $i$ 个字符串,第 $i$ 个不翻转(或者翻转)的情况下,最少的花费. AC代码: #include<bits/stdc++.h> using namespace std; typ…
题目链接:http://codeforces.com/problemset/problem/1096/D 题意: 给出一个小写字母组成的字符串,如果该字符串的某个子序列为 $hard$,就代表这个字符串是不好的. 现在你要删掉若干字母,使得字符串是好的,同时删除第 $i$ 个字母会使得歧义程度增加 $a[i]$,你需要让歧义程度最低,输出这个值. 题解: $dp[i][x=0,1,2,3]$ 的状态是前 $i$ 个字母,第二维 $x$ 代表:$0$——不包含任何有可能构成 “$hard$” 的子…
题目链接:http://codeforces.com/problemset/problem/793/C 题目大意:给你一个捕鼠器坐标,和各个老鼠的的坐标以及相应坐标的移动速度,问你是否存在一个时间点可以关闭捕鼠器抓住所有的老鼠,误差不能超过1e-6. 解题思路:可以把每个老鼠进入捕鼠器的时间和出捕鼠器的时间计算出来,那就可以把一只进出捕鼠器时间当成一个集合,把各个集合求交集得到的就是最后可以捕到所有老鼠的时间范围,再取交集左边界时间就可以了. 千万要注意一点:老鼠不能在边界上被捕捉,表示之前没看…
Portal:http://codeforces.com/problemset/problem/687/A 二分图染色 好模板题 有SPJ 值得注意的是,因为C++的奇妙的运算机制 若在vector变量x.size()=0,则x.size()-1会溢出(此处坑了我3h) 这不禁让我想起了文明2里的甘地 #include<iostream> #include<algorithm> #include<set> #include<cstdio> #include&…
Codeforces Round #804 (Div. 2) C(组合 + mex) 本萌新的第一篇题解qwq 题目链接: 传送门QAQ 题意: 给定一个\(\left [0,n-1 \right ]\)的排列,问有多少个排列,所有的子区间的mex值和原排列的mex值相同,求方案数对1e9 + 7 取模. 分析: 对于这个问题,我们要先知道,一个区间的mex是该区间没有出现过的最小正整数.所以对于\(\left [0,n-1 \right ]\)中的每个数字\(i\),我们要知道的是\(\lef…
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six sub…
E. Mike and Geometry Problem 题目连接: http://www.codeforces.com/contest/689/problem/E Description Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him an interesting geometry problem. Let's define f([l, r]) = r - l + 1 to…
D. Holidays Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/D Description Everyone knows that the battle of Endor is just a myth fabled by George Lucas for promotion of his movie. Actually, no battle of Endor has…
C. Simple Strings 题目连接: http://www.codeforces.com/contest/665/problem/C Description zscoder loves simple strings! A string t is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add a…
链接:https://codeforces.com/contest/1288/problem/D D. Minimax Problem 题意:给定n个数组,长度为m,从n中数组挑选两个数组,两个数组中的每一位取两者的最大值组成一个新的数组,新数组中的最小值记为c,所有组合中c的最大值 思路:题目中m的范围只有8,数组中元素的范围是1e9,显然m的范围非常特殊,似乎可以把数组用二进制的形式进行状态压缩,这里采用二分答案的方法.二分范围是数组元素最小值到最大值,每次check(mid)一遍,chec…
Problem J. Triatrip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/attachments Description The travel agency “Four Russians” is offering the new service for their clients. Unlike other agencies that only suggest one-way…
Problem C. Painting CottagesTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/attachments Description The new cottage settlement is organized near the capital of Flatland. The construction company that is building the settl…
题目链接:http://codeforces.com/contest/682/problem/D 给你两个字符串,求两个字符串中顺序k个的相同子串 长度之和.(注意是子串) dp[i][j][k][0] 表示a[i] == a[j]时,a字符串前i个和b字符串前j个,顺序k个相同的子串 长度之和 dp[i][j][k][1] 表示a[i] != a[j]时,顺序k个相同子串的长度之和 dp[i][j][k][0] = max(dp[i - 1][j - 1][k][0], dp[i - 1][j…
Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into s to make it a palindrome. A palindrome is a string that reads the same forward and backward. For…
Problem C. Painting CottagesTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/attachments Description The new cottage settlement is organized near the capital of Flatland. The construction company that is building the sett…
Problem F. Door LockTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/attachments Description It was a beautiful night at Yekaterinburg, the sky was crystal clear with no clouds, and the view of the moon and the stars was…
Problem A. Alien Communication Masterclass Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100610 Description Andrea is a famous science fiction writer, who runs masterclasses for her beloved readers. The most popular one is the…
Problem K. Kitchen Robot Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100610 Description Robots are becoming more and more popular. They are used nowadays not only in manufacturing plants, but also at home. One programmer wit…
Problem H. Horrible Truth Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100610 Description In a Famous TV Show “Find Out” there are n characters and only one Horrible Truth. To make the series breathtaking all way long, the sc…
Problem E. Explicit Formula Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100610 Description Consider 10 Boolean variables x1, x2, x3, x4, x5, x6, x7, x8, x9, and x10. Consider all pairs and triplets of distinct variables amon…
Problem F "Folding" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100002 Description Bill is trying to compactly represent sequences of capital alphabetic characters from 'A' to 'Z' by folding repeating subsequences insid…
Problem J. TriatripTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/attachments Description The travel agency “Four Russians” is offering the new service for their clients. Unlike other agencies that only suggest one-way…
Problem H. Hard TestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/attachments Description Andrew is having a hard time preparing his 239-th contest for Petrozavodsk. This time the solution to the problem is based on Di…
Problem E. MinimaTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/attachments Description You are given an array x[1 . . . n] and a number m. For all i from 1 to n−m+ 1 find the minimum among x[i], x[i + 1], . . . , x[i +…
Problem D. Dinner ProblemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/attachments Description A group of k students from Cooking University living in the campus decided that each day of the semester one of them will p…
题目链接: http://codeforces.com/contest/706/problem/C 题目大意: n(2 ≤ n ≤ 100 000)个字符串(长度不超过100000),翻转费用为Ci(<=109),求所有字符串从上到下符合字典序从小到大的最小费用.无解输出-1. 题目思路: [动态规划] 每个字符串有2种状态,翻转或者不翻转,每次只与上一个字符串是否翻转有关,可以用DP. 费用很大,要用long long. 无解的时候我直接break了WA了好久. // //by coolxxx…