当前位置:网站首页>Codeforce:b. mark the dust sweeper [fill 0 + move]
Codeforce:b. mark the dust sweeper [fill 0 + move]
2022-07-19 15:56:00 【White speed Dragon King's review】

analysis
Remove useless prefixes 0
then , In the middle of the 0 One by one ( As a delivery )
Make up one 0 Need an extra
Then fill in the middle 0 Then you can transfer effectively
So is a Sum of and then 0 If so, add one
ac code
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
# flatten
# find the pattern
# fill the 0 take 1 step
# after fill all the 0, can move from head to tail
ptr = 0
while ptr < n and a[ptr] == 0:
ptr += 1
ans = 0
for i in range(ptr, n - 1):
if a[i] == 0:
ans += 1
else:
ans += a[i]
print(ans)
summary
Construction question + Follow 0 He Fei 0 Dealing with
边栏推荐
- 洗澡的新发现
- CoCon: A Self-Supervised Approach for Controlled Text Generation | ICLR 2021
- 我应该怎么设计我的博客?如何搭建一个体验好的博客?
- 王者荣耀商城异地多活架构设计
- Offline installation of MariaDB
- Lambda function and for items Sort (key = lambda y:y[1], reverse = true).
- Design of the multi live architecture in different places of the king glory mall
- QT | qcombobox of control
- Series operations of stack and queue containers (detailed explanation)
- PAT乙级-B1005 继续(3n+1)猜想(25)【数组】
猜你喜欢

C # FTP dual network card problem

我应该怎么设计我的博客?如何搭建一个体验好的博客?

LVS负载均衡群集

阿叶的新发型

Why is Emoji called Emoji

OSPF comprehensive experiment

Online dice rolling dice tool

Upload files to remote devices through pyro4 command parameters

Open3d library installation, CONDA common instructions, importing open3d times this error solving environment: failed with initial frozen solve Retrying w

群里的初级工程师求助说,要采集采招数据,必须给他安排上
随机推荐
Identity server 4 uses openid connect to add user authentication (3)
Woman Yelling At a Cat
Set up intranet mail server "extmail free version" through Qunhui virtual machine
阿米的思考
国泰君安是正规证券公司嘛?开户安全吗?
Basic knowledge of Kunpeng code migration tool
获取近30天的日期列表
JVM个人学习笔记
cookie,localstorage封装
技术“砖家”解决问题的几个情景
MogDB/openGauss 权限整理
LBP feature notes
Sort subsequence and inverted string
我,35岁了。
Griddlyjs: Web ide based on Reinforcement Learning
JUC源码学习笔记2——AQS共享和Semaphore,CountDownLatch
Advanced customization of uni app [day13]
HCNP Routing&Switching之BFD
ADN公益加速 —— Jsdelivr npm(国内),ElmCDN的优质替代方案
注册开户打新债账号开户安全吗?是靠谱的吗?