当前位置:网站首页>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')
总结
前缀和思维 + 去掉一个挪到合适的位置 + 二分查
边栏推荐
- 功率放大器的设计要点
- 不需要服务器,教你仅用30行代码搞定实时健康码识别
- Xi'an Zongheng Information × JNPF: Adapt to the characteristics of Chinese enterprises, fully integrate the cost management and control system
- 进程间通信方式
- 第三章 Scala运算符
- To ensure that the communication mechanism
- 【TA-霜狼_may-《百人计划》】美术2.7 Metallic 与 Speculer流程
- numpy入门详细代码
- 06-总线
- 平稳发展 | 西欧地区手游玩家的数据和洞察
猜你喜欢

Li Mu's deep learning notes are here!

Redis的主从复制和集群

一文详解什么是软件部署

录音文件识别

【已解决】allure无法生成json文件和AttributeError: module ‘allure‘ has no attribute ‘severity_level‘

GPS satellite synchronization clock, NTP network synchronization clock, Beidou clock server (Jingzhun)

Typora收费?搭建VS Code MarkDown写作环境

Request method ‘POST‘ not supported。 Failed to load resource: net::ERR_FAILED

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

JVM Tuning-GC Fundamentals and Tuning Key Analysis
随机推荐
【Go事】一眼看穿 Go 的集合和切片
Difference between GET and POST requests
如何实时监控销售数据?销售看板来帮你!
邮差"头":{“retCode”:“999999”
DevOps平台中的制品库是什么?有什么用处?
LeetCode·84.柱状图中最大的矩形·单调递增栈
RSA306B,500,600系列API接口代码
74行代码实现浪漫的红心下落的动画效果
AAAI‘22 推荐系统论文梳理
面渣逆袭:MySQL六十六问,两万字+五十图详解
UWP 转换 IBuffer 和其他类型
"Research Report on the Development of Global Unicorn Enterprises in the First Half of 2022" released - DEMO WORLD World Innovation Summit ended successfully
皕杰报表配置文件report_config.xml里都配置了什么?
SAP ABAP SteamPunk 蒸汽朋克的最新进展 - 嵌入式蒸汽朋克
分支控制if-else
Redis的主从复制和集群
A detailed explanation of what is software deployment
Many merchants mall system function and dismantling 24 - ping the strength distribution of members
MetaAI科学家解读最新模型:200+语言互译,扩充千倍翻译数据,全球元宇宙用户自由交流
【打卡】广告-信息流跨域ctr预估(待更新)