CodeForces - 841B-Godsend-思维】的更多相关文章

题目链接:http://codeforces.com/problemset/problem/841/B Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move…
题意: 给你01字符串的长度再给你一个串. 然后你可以在这个串中选择一个起点和一个终点使得这个连续区间内所有的位取反. 求: 经过处理后最多会得到多少次01变换. 例如:0101是4次,0001是2次,000110是3次. 分析: 区间内部的数目是不会发生变化的,因为每一位都是按位取反,相当于都没变,唯一发生变化的是区间边缘,所以考虑到连续的两个或多个1或者0的时候在其中某处设置断点会使得变换次数增加,很容易理解当某处有两个连续点的时候变换次数增加1,因为一个区间只有两个端点所以变换次数最多增加…
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…
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…
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…
Polycarp likes to play with numbers. He takes some integer number xx, writes it down on the board, and then performs with it n−1n−1 operations of the two kinds: divide the number xx by 33 (xx must be divisible by 33); multiply the number xx by 22. Af…
The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If xx is the number of passengers in a bus just before the current bus stop and yy is…
E. Magic Stones time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Grigory has nn magic stones, conveniently numbered from 11 to nn. The charge of the ii-th stone is equal to cici. Sometimes G…
You are given an array a consisting of n elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array is the sum of imbalance valuesof all…
B. Makes And The Product time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output After returning from the army Makes received a gift — an array a consisting of n positive integer numbers. He hadn'…
You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ii-th lamp is sisi ('R', 'G' and 'B' — colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means chang…
D. Vladik and Favorite Game time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output This is an interactive problem. Vladik has favorite game, in which he plays all his free time. Game field could…
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path. You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except 1. Fi…
题目链接 这是一道很棒的二分题. 思路: 首先先思考什么情况下是可以无限的使用,即输出-1. 我们思考可知,如果每一秒内所有设备的用电量总和小于等于充电器每秒可以充的电,那么这一群设备就可以无限使用. 接下来分析不是无限使用的情况: 题目要求的是满足某个情况的最大值. 很像二分的类型,二分题目往往就是求某一个满足情况的最值,这样我们只需要寻找上限和下限,并对每一次mid值进行检验是否满足,这样的模型时间度一般为O(  N*Log( L )) L代表的是总区间的长度,而N代表的是完成一次判定需要的…
题意: 有n台机器,第i台机器每个单位时间消耗ai的功率,初始有bi的功率储备,有一个充电器每个单位时间充p单位的功率 问经过多长时间才能有一个功率位0的机器,如果能够无限使用输出-1: 解析: 时间是实数范围内,所以可以在任何时刻 给任何一个机器充电 所以如果p >= sum(a1 + a2 + a3 + ``` + an) 则能无限使用 如果不能无限使用 那么给所有的机器在不充电的情况下以初始能用多长时间从小到大排序 那么我们首先肯定要给使用时间最小的机器充电,使它用的时间能够大于等于时间第…
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and &qu…
题意: 有n门考试,每门考试都有两个时间,存在几门考试时间冲突,求考完所有的考试,所用的最后时间的最小值 解析: 对于时间冲突的考试 就是一个联通块 把每个考试看作边,两个时间看作点,那么时间冲突的考试即为一个连通块 对于一个连通块 1.如果边数等于点数 即为一个基环树,那么明显 这个连通块的最后时间为 权值最大的点 2.如果边数小于点数 即为一个树,那么连通块的最后时间为 权值次大的点(画画图) 3.如果边数大于点数 那么就冲突了, 输出-1就好了 离散化一下 #include <bits/s…
我真是一只菜狗......emm... 题意: 判断一个从1开始的队列是否可以按照bfs的顺序 进行遍历..必须从1开始...然后后边依次是bfs顺序 解析: 看代码能看懂吧...emm...就是把每个有关系的用map标记一下 然后bfs的时候 加一个循环进队列就好了  emm../. #include <bits/stdc++.h> #define rap(i, a, n) for(int i=a; i<=n; i++) #define rep(i, a, n) for(int i=a…
题面: You are given an array a with n distinct integers. Construct an array b by permuting a such that for every non-empty subset of indices S = {x1, x2, ..., xk} (1 ≤ xi ≤ n, 0 < k < n) the sums of elements on that positions in a and b are different,…
链接 大意: 给定n结点树, 求构造一种染色方案, 使得每个点颜色在[A,Z], 且端点同色的链中至少存在一点颜色大于端点 (A为最大颜色) 直接点分治即可, 因为最坏可以涂$2^{26}-1$个节点, 所以方案一定存在 #include <iostream> #include <algorithm> #include <cstdio> #include <vector> #define REP(i,a,n) for(int i=a;i<=n;++i)…
题意: 图中有n个点,开始有a个连通块,然后连着的边断开,不连的边连上,变为b个连通块,输出原图的邻接矩阵. 解析: 原图中连通块大于1的图,经过上述操作后,一定变成只有1个连通块的图. 若n != 2 || n != 3 则存在原图中连通块为1的图,经过上述操作后,一定变成只有1个连通块的图 所以a 和 b 肯定有一个为1 对于a != 1的情况,输出的时候只需要把前a-1个点 不连边 第a个到最后一个没相邻的两个连一条边 即可 因为a 和 b 是互补的 所以 a == 1时 swap交换一下…
原文地址:https://blog.csdn.net/weixin_39453270/article/details/80548442 博主已经讲的很好了 题意: 从一个序列中,选出一个集合,使得集合里的数两两差得绝对值为2得幂次 解析: 对于这个题目,我们需要发现这么一个结论,答案中形成的集合的大小最大只能达到3. 下面对这个命题进行简单的证明: 我们设当集合大小=3,三个数从小到大分别为a,b,c,即要符合条件,则需要满足: b-a=k1 (1) c-b=k2 (2) c-a=k3 (3)…
大致题意: 给出N个红点和M个蓝点,问可以有多少个红点构成的三角形,其内部不含有蓝点 假设我们现在枚举了一条线段(p[i],p[j]),我们可以记录线段下方满足(min(p[i].x,p[j].x)<x<=max(p[i].x,p[j].x) 的数量  时间复杂度为O(N*N*M) 那么我们就可以枚举三角形O(1)判断三角形内有无红点. #include<cstdio> #include<iostream> #include<cstring> #includ…
Welcoming autumn evening is the best for walking along the boulevard and npeople decided to do so. The boulevard can be represented as the axis Ox. For every person there are three parameters characterizing the behavior: ti, si, fi — the moment of ti…