Codeforces 135A-Replacement(思维)】的更多相关文章

题意: 给你01字符串的长度再给你一个串. 然后你可以在这个串中选择一个起点和一个终点使得这个连续区间内所有的位取反. 求: 经过处理后最多会得到多少次01变换. 例如:0101是4次,0001是2次,000110是3次. 分析: 区间内部的数目是不会发生变化的,因为每一位都是按位取反,相当于都没变,唯一发生变化的是区间边缘,所以考虑到连续的两个或多个1或者0的时候在其中某处设置断点会使得变换次数增加,很容易理解当某处有两个连续点的时候变换次数增加1,因为一个区间只有两个端点所以变换次数最多增加…
A. Replacement time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little Petya very much likes arrays consisting of n integers, where each of them is in the range from 1 to 109, inclusive. Re…
You are given qq queries in the following form: Given three integers lili, riri and didi, find minimum positive integer xixi such that it is divisible by didi and it does not belong to the segment [li,ri][li,ri]. Can you answer all the queries? Recal…
题目链接:http://codeforces.com/problemset/problem/1038/D 题意: 给出 $n$ 个史莱姆,每个史莱姆有一个价值 $a[i]$,一个史莱姆可以吃掉相邻的史莱姆,此时其自身的价值就要减掉被吃掉的那个史莱姆的价值. 史莱姆会不断的互相吞噬直到最后只剩一个,要求你该史莱姆可能的最大价值. 题解: 相当于你在 $n$ 个数前面添加 $+$ 或者 $-$,然后拼成一个算式计算答案. 首先考虑到的是,史莱姆的价值是全正或者全负的情况,这样的话,不可能使得所有价值…
题意:给出n(0≤n≤22)和m,和m个数ai,1 ≤ m ≤ 2n ,0≤ai<2n ,把ai & aj == 0 的连边,求最后有几个连通块 解析:一个一个去找肯定爆,那么就要转换一下思维,想一下什么样的数才能按位与ai为0 那么肯定是ai ^ ((1<<n)-1)的子集,所以去找它的所有子集即可 例1010  变成0101  子集有 0101  0100  0001 然后只有x是给出的那m个数种的时候 才能 ^ ,其他情况消1取子集 #include <bits/st…
Each month Blake gets the report containing main economic indicators of the company "Blake Technologies". There are n commodities produced by the company. For each of them there is exactly one integer in the final report, that denotes correspond…
Almost Acyclic Graph CodeForces - 915D time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a directed graph consisting of n vertices and m edges (each edge is directed, so it can…
Diagonal Walking v.2 CodeForces - 1036B Mikhail walks on a Cartesian plane. He starts at the point (0,0)(0,0), and in one move he can go to any of eight adjacent points. For example, if Mikhail is currently at the point (0,0)(0,0), he can go to any o…
https://vjudge.net/problem/2135388/origin Describe You are given an integer sequence 1,2,-,n. You have to divide it into two sets A and B in such a way that each element belongs to exactly one set and |sum(A)−sum(B)| is minimum possible. The value |x…
Let's suppose you have an array a, a stack s (initially empty) and an array b (also initially empty). You may perform the following operations until both a and s are empty: Take the first element of a, push it into s and remove it from a (if a is not…