当前位置:网站首页>codeforces:808D. Array Division【二分 + 找规律】
codeforces:808D. Array Division【二分 + 找规律】
2022-08-04 15:58:00 【白速龙王的回眸】

分析
一个东西可以往前or往后放
只要看减去这个东西的前缀和和后缀和是否存在half - num即可
注意:这个前缀和or后缀和不能包含当前数,否则会造成改变
ac code
import sys
from itertools import accumulate
from bisect import bisect_left
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
preSum = list(accumulate(a, initial = 0))
b = a[::-1]
preSum2 = list(accumulate(b, initial = 0))
tot = sum(a)
if tot % 2 != 0:
print('NO')
else:
half = tot // 2
flag = False
for i in range(n):
num = a[i]
target = half - num
idx = bisect_left(preSum, target)
if idx <= i and target == preSum[idx]:
flag = True
break
for i in range(n):
num = b[i]
target = half - num
idx = bisect_left(preSum2, target)
if idx <= i and target == preSum2[idx]:
flag = True
break
if flag:
print('YES')
else:
print('NO')
总结
前缀和思维 + 去掉一个挪到合适的位置 + 二分查
边栏推荐
猜你喜欢
随机推荐
Real-Time Rendering 4th related resource arrangement (no credit required)
【Go事】一眼看穿 Go 的集合和切片
全差分运放:THS4140
jasmine.any(Function) 的一个使用场景
Difference between GET and POST requests
In-depth analysis of HyperBDR cloud disaster recovery 1: Cloud-native cross-platform disaster recovery, making data flow more flexible
【伸手党福利】投影仪初学者入门——投影亮度及幕布选择——从入门到精通
qt 复杂界面信号槽设计
吴恩达机器学习[9]-神经网络学习
NFT blind box mining system dapp development NFT chain game construction
06-总线
H5 开发内嵌页面跨域问题
NFT盲盒挖矿系统dapp开发NFT链游搭建
学 Go,最常用的技能是什么?打日志
To ensure that the communication mechanism
为什么Redis默认序列化器处理之后的key会带有乱码?
What is an artifact library in a DevOps platform?What's the use?
番茄插件番茄助手下载
postman “header“:{“retCode“:“999999“
在Markdown文件中快速插入本地图片







![吴恩达机器学习[12]-机器学习系统设计](/img/6c/17f650e8c32f2bb0469a821305d58f.png)
