CodeForces #794 Div2 | 题解ABC

A. Everything Everywhere All But One

You are given an array of nn integers a1,a2,,ana1,a2,…,an. After you watched the amazing film "Everything Everywhere All At Once", you came up with the following operation.

In one operation, you choose n1n−1 elements of the array and replace each of them with their arithmetic mean (which doesn't have to be an integer).

For example, from the array [1,2,3,1][1,2,3,1] we can get the array [2,2,2,1][2,2,2,1],

if we choose the first three elements, or we can get the array [4/3,4/3,3,4/3], if we choose all elements except the third.

Is it possible to make all elements of the array equal by performing a finite number of such operations?

 

这题我的主要的思路就是先把所有的元素加起来记为sum,然后分别用sum减去每一位,用一个新的数组记下来double(sum-=a[i]) / double(n-1)

然后遍历这个新的数组,如果与对应下标的原来数组值相同,则是"YES",反之"NO"。


B. Odd Subarrays

For an array [b1,b2,,bm][b1,b2,…,bm] define its number of inversions as the number of pairs (i,j)(i,j) of integers such that 1i<jm1≤i<j≤m and bi>bjbi>bj. Let's call array bodd if its number of inversions is odd.

For example, array [4,2,7][4,2,7] is odd, as its number of inversions is 11, while array [2,1,4,3][2,1,4,3] isn't, as its number of inversions is 22.

You are given a permutation [p1,p2,,pn][p1,p2,…,pn] of integers from 11 to nn (each of them appears exactly once in the permutation). You want to split it into several consecutive subarrays (maybe just one), so that the number of the odd subarrays among them is as large as possible.

What largest number of these subarrays may be odd?

 

这题其实只需在每次读入一个数的时候,看一看和前面的最大值比大还是小,若不小于之前的最大值(则无法构成odd subarray)则最大值变为该值,

若小于之前的最大值,则可以形成一个odd subarray,同时cnt++,从前往后贪心,就可以把所有的做出来。

(一开始我想太复杂了qwq,果然就是要大胆假设,赛后求证)


 

C. Circular Local MiniMax

You are given nn integers a1,a2,,ana1,a2,…,an. Is it possible to arrange them on a circle so that each number is strictly greater than both its neighbors or strictly smaller than both its neighbors?

In other words, check if there exists a rearrangement b1,b2,,bnb1,b2,…,bn of the integers a1,a2,,ana1,a2,…,an such that for each ii from 11 to nn at least one of the following conditions holds:

  • bi1<bi>bi+1bi−1<bi>bi+1
  • bi1>bi<bi+1bi−1>bi<bi+1

To make sense of the previous formulas for i=1i=1 and i=ni=n, one shall define b0=bnb0=bn and bn+1=b1bn+1=b1.

 

这题大概就是先看n的奇偶性,n是奇数直接判NO;

否则我们排序数组,然后二分到中点,逐一push到新的数组里;

然后只需要逐位判断是不是局部max || 局部min,都是的话就是YES,否则中断输出NO,

如果YES,最后遍历输出新数组即可。

posted @   Conqueror712  阅读(121)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· winform 绘制太阳,地球,月球 运作规律
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
点击右上角即可分享
微信分享提示