Codeforces
来源:互联网 发布:python中字符串的函数 编辑:程序博客网 时间:2024/06/03 17:08
Number of Ways
题目链接
分类:思维、暴力
1.题意概述
- 给你n个数a[1…n],要你找符合条件的
i,j(2≤i≤j≤n−1) ,满足∑k=1i−1ak=∑k=ijak=∑k=j+1nak ,求符合条件的i,j 的组合数?
2.解题思路
- 本意就是要你找三段使得他们和相等,那么数列首先得能被分成三段,也就是
sum%3=0 才行,然后再按组合统计即可,细节可以参见代码。
3.AC代码
#include <bits/stdc++.h>#define INF 0x3f3f3f3f#define maxn 500010#define lson root << 1#define rson root << 1 | 1#define lent (t[root].r - t[root].l + 1)#define lenl (t[lson].r - t[lson].l + 1)#define lenr (t[rson].r - t[rson].l + 1)#define N 1111#define eps 1e-6#define pi acos(-1.0)#define e exp(1.0)using namespace std;const int mod = 1e9 + 7;typedef long long ll;typedef unsigned long long ull;int a[maxn];ll sum[maxn];int main(){#ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); long _begin_time = clock();#endif int n; scanf("%d", &n); sum[0] = 0; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); sum[i] = sum[i - 1] + a[i]; } ll cnt = 0; if (sum[n] % 3 == 0) { ll tmp1 = sum[n] / 3; ll tmp2 = tmp1 << 1; int count = 0; for (int i = 1; i < n; i++) { if (sum[i] == tmp2) cnt += count; if (sum[i] == tmp1) count++; } } printf("%I64d\n", cnt);#ifndef ONLINE_JUDGE long _end_time = clock(); printf("time = %ld ms.", _end_time - _begin_time);#endif return 0;}
阅读全文
0 0
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- 运行中的Nginx进程间的关系
- 【PAT甲级】1076. Forwards on Weibo (30)
- ThinkPHP 3.1.2 输出和模型使用1
- Word页码设置技巧
- Spring Aop 初探(1)
- Codeforces
- Linux man
- Java开发环境配置-讲解
- android进阶:利用rxjava写一个超简单的bus
- range
- Ubuntu用户及用户组管理命令
- 按每天特定时间作为分界来统计数据的sql语句[sqlserver]
- 2017.7.5工作日记
- Vue中render方法的使用