D. Equalize Them All time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given an array aa consisting of nn integers. You can perform the following operations arbitrary number of times…
题意:有一组数,可以选择某个数\(a_i\)相邻的一个数\(a_j\),然后可以让\(a_i\)加上或者减去\(|a_i-a_j|\),问最少操作多少次使得数组中所有数相同. 题解:不难发现,每次操作必然可以使得一个数等于它旁边的任意一个数,所以让数组中的其他数等于出现次数最多的那个数一定是最优的,然后我们就去找与那个数相邻的数去求块,正着反着模拟输出一下就可以了,具体看代码吧. 代码: int n; int a[N]; map<int,int> mp; int mx,res; bool st…
D. Equalize Them All time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given an array aa consisting of nn integers. You can perform the following operations arbitrary number of times…
A. Diverse Strings time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output A string is called diverse if it contains consecutive (adjacent) letters of the Latin alphabet and each letter occurs exac…
http://codeforces.com/contest/1144 A. Diverse Strings A string is called diverse if it contains consecutive (adjacent) letters of the Latin alphabet and each letter occurs exactly once. For example, the following strings are diverse: "fced", &qu…
链接: https://codeforces.com/contest/1234/problem/A 题意: You are both a shop keeper and a shop assistant at a small nearby shop. You have n goods, the i-th good costs ai coins. You got tired of remembering the price of each product when customers ask fo…
原文链接https://codeforces.com/contest/1183/problem/B 题意:进行Q组测试,在每组中有长度为n的数组a[i],然后现在给你一个K,问你找到一个bi使得|ai-bi|<=k并且bi最大.如果找不到,就输出-1.思路:这个也就关系到,最大值max,最小值min,和K,至于中间的数,我们不用去管,现在一个排序,如果max-min<=2*k,那么就输出min+k,否者就输出-1.(为什么要在2*k的范围找???想想看)代码: #include"io…
        F. Graph Without Long Directed Paths time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a connected undirected graph consisting of nn vertices and mm edges. There are no…
F. Graph Without Long Directed Paths time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a connected undirected graph consisting of nn vertices and mm edges. There are no self-lo…
Median String time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given two strings ss and tt, both consisting of exactly kk lowercase Latin letters, ss is lexicographically less than …