Codeforce :466C. Number of Ways (数学)
https://codeforces.com/problemset/problem/466/C
解题说明:此题是一道数学题,若平分分成若干种情况,应当整体(sum)考虑,对sum/3进行分析。它是区分3段的标准。
所以当部分和tmp=sum/3,部分统计加一。
当 tmp==sum*2/3,则全部统计ans+=部分统计(s)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e5 + 10;
ll sum[N];
int main() {
//freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false), cin.tie(0);
int n; cin >> n;
for (int i = 1; i <= n; ++i) {
ll x; cin >> x;
sum[i] = sum[i - 1] + x;
}
ll ans = 0, num = 0;
for (int i = 1; i < n; ++i) {
if (sum[i] * 3 == 2 * sum[n]) ans += num;
if (sum[i] * 3 == sum[n]) num++;
}
cout << ans << endl;
}
Codeforce :466C. Number of Ways (数学)的更多相关文章
- codeforces 466C. Number of Ways 解题报告
题目链接:http://codeforces.com/problemset/problem/466/C 题目意思:给出一个 n 个数的序列你,问通过将序列分成三段,使得每段的和都相等的分法有多少种. ...
- Codeforces - 466C - Number of Ways - 组合数学
https://codeforces.com/problemset/problem/466/C 要把数据分为均等的非空的三组,那么每次确定第二个分割点的时候把(除此之外的)第一个分割点的数目加上就可以 ...
- [Codeforces 466C] Number of Ways
[题目链接] https://codeforces.com/contest/466/problem/C [算法] 维护序列前缀和 , 枚举中间一段即可 , 详见代码 时间复杂度 : O(N) [代码] ...
- cf466C Number of Ways
C. Number of Ways time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Round #266 (Div. 2) C. Number of Ways
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split ...
- LeetCode 5274. Number of Ways to Stay in the Same Place After Some Steps - Java - DP
题目链接:5274. 停在原地的方案数 You have a pointer at index 0 in an array of size arrLen. At each step, you can ...
- 【leetcode】1269. Number of Ways to Stay in the Same Place After Some Steps
题目如下: You have a pointer at index 0 in an array of size arrLen. At each step, you can move 1 positio ...
- codeforce Number of Ways(暴力)
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #d ...
- 【Codeforces 466C】Number of Ways
[链接] 我是链接,点我呀:) [题意] 让你把数组分成3个连续的部分 每个部分的和要一样 问你有多少种分法 [题解] 先处理出来num[i] 表示i..n这里面有多少个j 满足aft[j] = af ...
- POJ1351 Number of Locks(数学)
截至写博客为止,貌似这是网上第一个采用数学公式来处理的. 网上的题解都是DFS或是动态规划,但感觉可以推公式直接用数学的方法处理,想了好久,终于推出公式. 题意:一个长度为n的由数字1,2,3,4 组 ...
随机推荐
- 安全测试工具Burpsuit和OWASP ZAP使用入门指南
Burpsuit使用入门指南 安装: 网上有很多相关相关保姆级别教程,所以这里不加赘述了 尽量使用java8版本,破解版兼容8做的比较好 如果发现注册机无法打开或者能打开注册机[run]无法点击唤起软 ...
- 使用 Kubernetes 为 CI/CD 流水线打造高效可靠的临时环境
介绍 在不断发展的科技世界中,快速构建高质量的软件至关重要.在真实环境中测试应用程序是及早发现和修复错误的关键.但是,在真实环境中设置 CI/CD 流水线进行测试可能既棘手又昂贵. Kubernete ...
- [CF1748E] Yet Another Array Counting Problem
题目描述 The position of the leftmost maximum on the segment $ [l; r] $ of array $ x = [x_1, x_2, \ldots ...
- [ABC261A] Intersection
Problem Statement We have a number line. Takahashi painted some parts of this line, as follows: Firs ...
- Liunx--centos7服务器上 安装 jenkins,实现持续集成发布
1.下载并安装jenkins wget -v https://pkg.jenkins.io/redhat-stable/jenkins-2.176.3-1.1.noarch.rpmrpm -ivh j ...
- 【Python】【OpenCV】轮廓检测
Code: 1 import cv2 2 import numpy as np 3 4 img = np.zeros((200, 200), dtype=np.uint8) 5 img[50:150, ...
- Python笔记二之多线程
本文首发于公众号:Hunter后端 原文链接:Python笔记二之多线程 这一篇笔记介绍一下在 Python 中使用多线程. 注意:以下的操作都是在 Python 3.8 版本中试验,不同版本可能有不 ...
- Python——第四章:函数的递归调用
递归: 函数自己调用自己 递归如果没有任何东西拦截的话. 它默认就是一个死循环 def func() func() func() 因此递归调用的时候需要有判断,来退出循环 def func() if ...
- SQL Server系列:系统函数之字符串函数
1.ascii() :返回ascii码 --返回ascii码 select ascii('a') go 2.char() :返回ascii对应的字符 --返回ascii对应的字符 select ch ...
- C++产生N以内的随机整数
C++产生N(这里N=100)以内的随机整数的例子: #include <iostream> #include <ctime> using namespace std; int ...