当前位置:网站首页>Codeforces 1637 B. mex and array - reading, violence
Codeforces 1637 B. mex and array - reading, violence
2022-06-12 13:32:00 【Tianyi City*】
The question :
Give you a length of n Array of a. Ask you the value and maximum of all its sub segments .
value :
Divide an array into sections , The value of each interval is the length of the interval + In this range MEX. The value of an array is the sum of the values of all intervals .
Answer key :
this tnd I read the topic for half a day .
Since we need to find the maximum , Let's see if it's better to divide into multiple intervals , Let's let the MEX Bigger and better . for instance :
0 1 2 3 4
Does this look like an interval MEX The largest is probably the best ? The answer is interval numbers 1+ Section MEX5=6
What if an interval has only one number ? That is interval number 5+ Section MEX{1,0,0,0,0}=6
It looks the same .
Let's think about this problem : Suppose the current interval length is x, If you move one space to the right , Is it better to become a new section or let MEX May be +1 good .
We can find out ,MEX once +1, That means interval numbers don't +1, If the interval number +1,MEX Won't +1.
however MEX We have to verify it , Very tired, . So it's better to direct a number to an interval .
#include<bits/stdc++.h>
using namespace std;
const int N=105;
int a[N];
int main()
{
int t;
scanf("%d",&t);
while(t--){
int n,ans=0;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
int z=0;
for(int j=i;j;j--){
z+=a[j]==0;
ans+=i-j+1+z;
}
}
printf("%d\n",ans);
}
return 0;
}
边栏推荐
- Implementing tensorflow deep learning framework similarflow with numpy
- Computational hierarchy -- the problem of large numbers multiplying decimals
- Introduction to application design scheme of intelligent garbage can voice chip, wt588f02b-8s
- 安装MySQL时出错,照着下面这个链接,做到cmd就不行了
- [brush title] probability of winning a draw
- IC chip scheme fs4062b for lithium battery charging with 5V boost to 12.6V
- Does jupyternotebook have a Chinese character database. Can you recognize handwritten Chinese in deep learning
- 【刷题篇】超级洗衣机
- Octopus network progress monthly report | may 1-May 31, 2022
- 【云原生 | Kubernetes篇】深入了解Ingress
猜你喜欢
简历 NFT 平台 TrustRecruit 加入章鱼网络成为候选应用链
2061: [example 1.2] trapezoidal area
How to balance multiple losses in deep learning?
Successful job hopping Ali, advanced learning
Openstack network
Resume NFT platform trustrecruit joined Octopus network as a candidate application chain
[EDA] chip layout design: VLSI layout design using electric
How to solve the problem of data table query error when SQLite writes the registration function?
torch_ About the geometric Mini batch
颜色编码格式介绍
随机推荐
GPUImage链式纹理的简单实现
Rk3399 platform development series explanation (kernel debugging chapter) 2.50 use of systrace
Informatics Olympiad all in one 2059: [example 3.11] buy a pen
Experience and learning path of introductory deep learning and machine learning
简历 NFT 平台 TrustRecruit 加入章鱼网络成为候选应用链
The goods are full. You must take this knowledge
Summary of question brushing in leetcode sliding window
Getting started with NVIDIA Jetson nano Developer Kit
Qualcomm platform development series (Protocol) QMI brief introduction and usage
Return value of WaitForSingleObject
import torch_ Geometric first graph network example
Application of short circuit expression (||) in C language
Application of list and Dict
Cocoapods的相关知识点
Hudi key generation
go-zero 微服务实战系列(二、服务拆分)
torch_ geometric message passing network
Web3.0,「激发创造」的时代
2063: [example 1.4] cattle eat grass
在 Debian 10 上独立安装MySQL数据库