当前位置:网站首页>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个改变的只有前缀和看得出来
对称的往往抵消
不对称的会露出马脚
我们就把它逮住
前缀和的和
边栏推荐
- 7月30号|来一场手把手助您打造智能视觉新爆款的技术动手实验
- odoo coding conventions (programming conventions, coding guidelines)
- [National Programming] "Software Programming - Lecture Video" [Zero Basic Introduction to Practical Application]
- MySQL数据库————存储过程和函数
- MySQL数据库————流程控制
- explain each field introduction
- ExcelPatternTool: Excel form-database mutual import tool
- ExcelPatternTool: Excel表格-数据库互导工具
- Choosing the right DevOps tool starts with understanding DevOps
- WinRAR | Generate multiple installers into one installer
猜你喜欢

Prometheus's Recording rules practice

MySQL数据库————存储过程和函数

【蓝桥杯选拔赛真题47】Scratch潜艇游戏 少儿编程scratch蓝桥杯选拔赛真题讲解

Prometheus的Recording rules实践
![[Neural Network] This article will take you to easily analyze the neural network (with an example of spoofing your girlfriend)](/img/2c/18ce72dfd0889d901ea0d95721ed19.png)
[Neural Network] This article will take you to easily analyze the neural network (with an example of spoofing your girlfriend)

DAO开发教程【WEB3.0】

网站建设流程

odoo 编码规范(编程规范、编码指南)

生命周期和作用域

将ENS域名转化为音乐需要几步?
随机推荐
安装GBase 8c数据库的时候,报错显示“Resource:gbase8c already in use”,这怎么处理呢?
C#/VB.NET: extracted from the PDF document all form
COS 用户实践征文
GZIPOutputStream 类源码分析
TestNG多个xml进行自动化测试
[National Programming] "Software Programming - Lecture Video" [Zero Basic Introduction to Practical Application]
PanGu-Coder:函数级的代码生成模型
Become a Contributor in 30 minutes | How to participate in OpenHarmony's open source contributions in multiple ways?
Tencent Cloud Hosting Security x Lightweight Application Server | Powerful Joint Hosting Security Pratt & Whitney Version Released
Zabbix6.0 DingTalk robot alarm
[Server data recovery] Data recovery case of offline multiple disks in mdisk group of server Raid5 array
Summer vacation first week wrap-up blog
MySQL数据库————流程控制
Win11校园网无法连接怎么办?Win11连接不到校园网的解决方法
Choosing the right DevOps tool starts with understanding DevOps
How to make the fixed-point monitoring equipment display the geographic location on the EasyCVR platform GIS electronic map?
【LeetCode】Day109-the longest palindrome string
Multi-Party Threshold Private Set Intersection with Sublinear Communication-2021: Interpretation
What should I do if the Win11 campus network cannot be connected?Win11 can't connect to campus network solution
Win11如何开启剪贴板自动复制?Win11开启剪贴板自动复制的方法