当前位置:网站首页>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')
总结
前缀和思维 + 去掉一个挪到合适的位置 + 二分查
边栏推荐
猜你喜欢

RepVGG学习笔记

有哪些好用的IT资产管理平台?

界面组件DevExpress ASP.NET Core v22.1 - 增强数据导出功能

西安纵横资讯×JNPF:适配中国企业特色,全面集成费用管控体系

GPS卫星同步时钟,NTP网络同步时钟,北斗时钟服务器(京准)

postman “header“:{“retCode“:“999999“

使用百度EasyDL实现森林火灾预警识别

为什么Redis默认序列化器处理之后的key会带有乱码?

ITSM软件与工单系统的区别是什么?

Request method ‘POST‘ not supported。 Failed to load resource: net::ERR_FAILED
随机推荐
招募 | 香港理工大学Georg Kranz 博士诚招博士
DocuWare Platform - Content Services and Workflow Automation Platform for Document Management (Part 1)
postman “header“:{“retCode“:“999999“
2022-08-04日报:量化细胞内的信息流:机器学习时代下的研究进展
西安纵横资讯×JNPF:适配中国企业特色,全面集成费用管控体系
功率放大器的设计要点
云存储硬核技术内幕——(13) 抓手,组合拳与闭环
农产品期货开户哪家好??
HyperBDR云容灾深度解析一:云原生跨平台容灾,让数据流转更灵活
把boot和APP一起烧录进MCU
皕杰报表配置文件report_config.xml里都配置了什么?
面渣逆袭:MySQL六十六问,两万字+五十图详解
SAP HANA Schemas 和 HDI Containers
Check which user permissions are assigned to each database, is there an interface for this?
ITSM软件与工单系统的区别是什么?
No server is required, teach you to get real-time health code recognition with only 30 lines of code
不需要服务器,教你仅用30行代码搞定实时健康码识别
RSA306B,500,600系列API接口代码
不需要服务器,教你仅用30行代码搞定实时健康码识别
Xi'an Zongheng Information × JNPF: Adapt to the characteristics of Chinese enterprises, fully integrate the cost management and control system