当前位置:网站首页>cf:D. Magical Array【数学直觉 + 前缀和的和】
cf:D. Magical Array【数学直觉 + 前缀和的和】
2022-08-01 19:01:00 【白速龙王的回眸】
分析
nonspecial的一个把1前挪一个单位,一个把1后挪一个单位
special的一个把1前挪一个单位,一个把1后挪2个单位
怎么区分special?
很明显第一个nonspecial的前缀和的和会抵消,保持原样
本来前挪1会导致变大1,但后挪1又会变小1
然而后挪2会导致变小2,所以special的前缀和的和会比其他的小
并且差就是移动的个数
ac code
import sys
from itertools import accumulate
from collections import Counter
input = sys.stdin.readline
for _ in range(int(input())):
n, m = list(map(int, input().split()))
c = [[0] * m for _ in range(n)]
for i in range(n):
c[i] = list(map(int, input().split()))
preSum = [[0] * m for _ in range(n)]
for i in range(n):
preSum[i] = list(accumulate(c[i]))
preSumSum = [0] * n
for i in range(n):
preSumSum[i] = sum(preSum[i])
c = Counter(preSumSum)
row, special, nonspecial = -1, -1, -1
for i in range(n):
if special != -1 and nonspecial != -1:
break
if c[preSumSum[i]] == 1:
row = i + 1
special = preSumSum[i]
else:
nonspecial = preSumSum[i]
print(row, nonspecial - special)
总结
数学的直觉
怎么区分?这里挪动1个改变的只有前缀和看得出来
对称的往往抵消
不对称的会露出马脚
我们就把它逮住
前缀和的和
边栏推荐
- 驱动上下游高效协同,跨境B2B电商平台如何释放LED产业供应链核心价值?
- Industry Salon Phase II丨How to enable chemical companies to reduce costs and increase efficiency through supply chain digital business collaboration?
- Zabbix6.0钉钉机器人告警
- Selenium在远程中的截图
- explain 各字段介绍
- XML配置
- AntDB database appeared in the 24th high-speed exhibition, helping smart high-speed innovative applications
- 硬件大熊原创合集(2022/07更新)
- 在表格数据上,为什么基于树的模型仍然优于深度学习?
- 首篇 NLP 领域图神经网络综述:127 页,从图构建到实际应用面面观
猜你喜欢
亚马逊云科技Build On2022技能提升计划第二季——揭秘出海爆款新物种背后的黑科技
【pyqt5】自定义控件 实现能够保持长宽比地缩放子控件
Three solutions: npm WARN config global --global, --local are deprecated. Use --location=global instead.
Library website construction source code sharing
从普通进阶成优秀的测试/开发程序员,一路过关斩将
7月30号|来一场手把手助您打造智能视觉新爆款的技术动手实验
Keras deep learning practice - traffic sign recognition
MySQL数据库————流程控制
What should I do if the Win11 campus network cannot be connected?Win11 can't connect to campus network solution
explain 各字段介绍
随机推荐
odoo coding conventions (programming conventions, coding guidelines)
Library website construction source code sharing
explain each field introduction
LeetCode 0152. Product Maximum Subarray: dp + Roll in Place
WinRAR | Generate multiple installers into one installer
安徽建筑大学&杭州电子科技大学|基于机器学习方法的建筑可再生能源优化控制
C#/VB.NET:从 PDF 文档中提取所有表格
硬件大熊原创合集(2022/07更新)
kubernetes-部署nfs存储类
生命周期和作用域
AntDB数据库亮相24届高速展,助力智慧高速创新应用
GZIPOutputStream 类源码分析
【综述专栏】IJCAI 2022 | 图结构学习最新综述:研究进展与未来展望
有点奇怪!访问目的网址,主机能容器却不行
【服务器数据恢复】服务器Raid5阵列mdisk组中多块磁盘离线的数据恢复案例
在全志V853开发板试编译QT测试
What should I do if the Win11 campus network cannot be connected?Win11 can't connect to campus network solution
SQL function TO_DATE (1)
力扣刷题之求两数之和
483-82 (23, 239, 450, 113)