ACM思维题训练集合 Desciption You've got an n × m pixel picture. Each pixel can be white or black. Your task is to change the colors of as few pixels as possible to obtain a barcode picture. A picture is a barcode if the following conditions are fulfilled: A…
题目地址:24道CF的DIv2 CD题有兴趣可以做一下. ACM思维题训练集合 Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He ha…
ACM思维题训练集合 After passing a test, Vasya got himself a box of n candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself. This me…
ACM思维题训练集合 A bracket sequence is a string, containing only characters "(", ")", "[" and "]". A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting…
ACM思维题训练集合 You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that: First we build by the array a an array s of partial sums, consisting of n elements. Element number…
ACM思维题训练集合 To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers…
ACM思维题训练集合 Furik and Rubik love playing computer games. Furik has recently found a new game that greatly interested Rubik. The game consists of n parts and to complete each part a player may probably need to complete some other ones. We know that the…
刚开始三重循环tle test11.后来想了个双重循环的方法. 解题思路: 1.双重循环一次,用一个一位数组存j和比j小的i的和的最小值. 2.再双重循环一次,找到比j大的数k,更新结果为ans=min(ans, k+比j小的i的和的最小值). 3.如果第二次循环没有更新ans,输出-1:若更新了输出ans. 代码: #include <bits/stdc++.h> using namespace std; typedef long long ll; #define MAX 200000000…
Nastya received a gift on New Year - a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month). Unfortunately, right a…
ACM思维题训练集合 It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are n displays placed along a road, and the i-th of them c…
C. Three displays time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to ren…
[链接] 我是链接,点我呀:) [题意] [题解] 动态规划 设dp[i][j]表示前i个数字,选了j个的最小花费. dp[i][j] = min(dp[k][j-1]+b[i]);//其中a[i]>a[k]且k<i 这其实就是枚举选取的第j-1个位置在哪个地方. 显然只有在它的前面,且满足a[i]>a[k]的位置k才有可能. 复杂度O(N^2) [代码] #include <bits/stdc++.h> using namespace std; const int N =…
Three displays time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent t…
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads. Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But…
Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven which can bake several types of cakes, and opened the bakery. Soon the expenses started to overcome the income, so Slastyona decid…
Let's call the roundness of the number the number of zeros to which it ends. You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible. Input…
题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0),先从1开始找到已经套好的娃娃层数, 其他是2次操作,还要减去k-1个娃娃是只要套上就可以 详细解释:http://blog.csdn.net/firstlucker/article/details/46671251 */ #include <cstdio> #include <algor…
题目链接:https://codeforces.com/problemset/problem/1197/D 题意: 给你一个序列,求一个子序列 a[l]~a[r] 使得该子序列的 sum(l,r)-k*(r-l+1)/m(向上取整)的值是在所有子序列中最大的,并输出最大值 思路: 法一:动态规划 dp[i][j] 表示序列到i截止,这一轮已经进行了j次取数(j = (len+m-1)%m) 那么dp[i][j]维护的就是起点为 s = i-j+1-m*t (t>=0)这个集合的最优,这样所有的…
原文链接http://www.cnblogs.com/zhouzhendong/p/8848990.html 题目传送门 - CodeForces 623E 题意 给定$n,k$. 让你构造序列$a(0<a_i<2^k)$,满足$b_i(b_i=a_1\ or\ a_2\ or\ \cdots\ or\ a_i)$严格单调递增.($or$为按位或) 问你方案总数.对$10^9+7$取模. $n\leq 10^{18},k\leq 30000$ 题解 毛爷爷论文题. 我怀疑我看到的是假论文.里面…
题目传送门 传送门 题目大意 餐厅有$n$张桌子,第$i$张桌子可以容纳$c_i$个人,有$t$组客人,每组客人的人数等概率是$[1, g]$中的整数. 每来一组人数为$x$客人,餐厅如果能找到最小的$c_j$使得$c_j \geqslant x$,那么就会把这张桌子分配给这些客人,并得到$x$的收益. 问期望的收益. 好像可以枚举每一种人数,然后算一下,但时间复杂度很爆炸. 先添加若干个容量为$\infty$的桌子.这样每组人一定能够分配到一张桌子,只是可能没有收益. 考虑最后答案一定是将桌子…
原文链接https://www.cnblogs.com/zhouzhendong/p/CF264C.html 题目传送门 - CF264C 题意 给定一个有 $n$ 个元素的序列,序列的每一个元素是个球,第 $i$ 个球具有 $v_i$ 的值,颜色为 $c_i$ . 一个序列的价值为每一个球价值和. 在一个序列中,第 $i$ 个球的价值为: 当 $c_i=c_{i-1}(i>1)$ 时,$value=a\times v_i$. 否则, $value=b\times v_i$ . 接下来有 $q$…
原文链接https://www.cnblogs.com/zhouzhendong/p/9246484.html 题目传送门 - Codeforces 1000G Two-Paths 题意 给定一棵有 $n(2\leq n\leq 3\times 10^5)$ 个节点的树,其中节点 $i$ 有权值 $a_i$,边 $e$ 有权值 $w_e$.$(1\leq a_i,w_e\leq 10^9)$ 现在给出 $q(1\leq q\leq 4\times 10^5)$ 组询问,每组询问给定两个数 $x,…
题目链接:https://codeforces.com/contest/978/problem/G 题目大意:n天m门考试,每门考试给定三个条件,分别为:1.可以开始复习的日期.2.考试日期.3.必须要复习的时间.根据以上条件,给出每天的安排,每天可以做三件事:1.考试.2.复习.3.休息 题解:先假设每天都在休息,然后依次填东西,策略是最先考试的最先复习 AC代码: #include<cstdio> #include<cstring> #include<algorithm&…
题目链接:https://codeforces.com/contest/978/problem/F 题目大意: n个程序员,k对仇家,每个程序员有一个能力值,当甲程序员的能力值绝对大于乙程序员的能力值时,甲可以做乙的爸爸,对于每个程序员,它可以做多少人的爸爸?(仇家之间不能做父子) 题解: 第一次:WA 失误 第二次:TL 找有效徒弟和仇家时,太复杂 第三次:ML 找有效徒弟依然复杂,找仇家简单了,但是内存超了 第四次:TL 解决了内存问题,找有效徒弟复杂,找仇家简单,时间超了(最接近成功的一次…
codeforces 17C Balance 题意 给定一个串,字符集{'a', 'b', 'c'},操作是:选定相邻的两个字符,把其中一个变成另一个.可以做0次或者多次,问最后可以生成多少种,使得任意一种字符和其他字符的个数相差都不超过1. 题解 一个生成串压缩之后必定都是初始串的子序列,那么只要能枚举所有子序列,其他的很好搞定. 对于枚举的每个子序列,如果它是由初始串最早能生成的产生,那么肯定不会重. 基于这一点,f(i, a, b, c)表示当前由初始串1~i生成子序列,三个字符分别的个数…
题目链接:https://codeforces.com/contest/978/problem/D 题解: 题目的大意就是:这组序列能否组成等差数列?一旦构成等差数列,等差数列的公差必定确定,而且,对于给定的数列,公差的可能性是已知的. 我的解决思路是:对于给定的数列,最后一位数 - 第一位数 / (n -1) 必定是公差,而对于我们要判断的原数列,其最后一位 - 第一位数的值是可以-2,-1,0,+1,+2的,穷举可能性一切公差,找出变动最小的情况.代码如下(有点小复杂,没优化): #incl…
Codeforces 762D 题目大意: 给定一个\(3*n(n \leq 10^5)\)的矩形,从左上角出发到右下角,规定每个格子只能经过一遍.经过一个格子会获得格子中的权值.每个格子的权值\(a_{ij}\)满足\(-10^9 \leq a_{ij} \leq 10^9\).最大化收益 题解: 乍一看,好麻烦! 最主要的是因为他能够往回走. 但是我们画图可以发现:每次往回走一定不用超过1次. 也就是说,最多只能走成这样 而不会走成这样 因为下图的走法一定可以用上图组合,并且 由于只用3行的…
ACM思维题训练集合 A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and &…
ACM思维题训练集合 C. A Mist of Florescence time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output As the boat drifts down the river, a wood full of blossoms shows up on the riverfront. "I've been here on…
ACM思维题训练集合 You are given k sequences of integers. The length of the i-th sequence equals to ni. You have to choose exactly two sequences i and j (i≠j) such that you can remove exactly one element in each of them in such a way that the sum of the chan…