当前位置:网站首页>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个改变的只有前缀和看得出来
对称的往往抵消
不对称的会露出马脚
我们就把它逮住
前缀和的和
边栏推荐
- 消息模板占位符的使用
- 无需破解,官网安装Visual Studio 2013社区版
- Stop using MySQL online DDL
- C#/VB.NET 从PDF中提取表格
- shell脚本专题(07):文件由cfs到bos
- DAO development tutorial [WEB3.0]
- What are the application advantages of SaaS management system?How to efficiently improve the digital and intelligent development level of food manufacturing industry?
- 首篇 NLP 领域图神经网络综述:127 页,从图构建到实际应用面面观
- 面试必问的HashCode技术内幕
- Three solutions: npm WARN config global --global, --local are deprecated. Use --location=global instead.
猜你喜欢

log factory (detail)

电商库存系统的防超卖和高并发扣减方案

【综述专栏】IJCAI 2022 | 图结构学习最新综述:研究进展与未来展望

在Map传值与对象传值中模糊查询

MLX90640 Infrared Thermal Imager Temperature Measurement Module Development Notes (Complete)

MySQL数据库————流程控制

【神经网络】一文带你轻松解析神经网络(附实例恶搞女友)

483-82(23、239、450、113)

kubernetes - deploy nfs storage class

Zabbix6.0钉钉机器人告警
随机推荐
LeetCode 0152. Product Maximum Subarray: dp + Roll in Place
三种方案解决:npm WARN config global --global, --local are deprecated. Use --location=global instead.
MySQL中超键、主键及候选键的区别是什么
Keras深度学习实战——交通标志识别
Three solutions: npm WARN config global --global, --local are deprecated. Use --location=global instead.
7月30号|来一场手把手助您打造智能视觉新爆款的技术动手实验
Choosing the right DevOps tool starts with understanding DevOps
30分钟成为Contributor|如何多方位参与OpenHarmony开源贡献?
Use of message template placeholders
【神经网络】一文带你轻松解析神经网络(附实例恶搞女友)
【服务器数据恢复】服务器Raid5阵列mdisk组中多块磁盘离线的数据恢复案例
modbus总线模块DAM-8082
123123123123
网站建设流程
[Server data recovery] Data recovery case of offline multiple disks in mdisk group of server Raid5 array
AntDB数据库亮相24届高速展,助力智慧高速创新应用
Win11如何删除升级包?Win11删除升级包的方法
Summer vacation second week wrap-up blog
Map传值
重保特辑|筑牢第一道防线,云防火墙攻防演练最佳实践