【链接】 我是链接,点我呀:)

【题意】

让你把数组分成3个连续的部分
每个部分的和要一样
问你有多少种分法

【题解】

先处理出来num[i]
表示i..n这里面有多少个j
满足aft[j] = aft[i]/2
这aft[i]=a[j]+a[j+1]..+a[n]
然后for从1..n
看看pre[i]*2=aft[i+1]是否成立。
如果成立的话那么答案就加上num[i+1]

【代码】

import java.io.*;
import java.util.*; public class Main { static int N = (int)5e5;
static InputReader in;
static PrintWriter out; public static void main(String[] args) throws IOException{
in = new InputReader();
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
} static class Task{
public void solve(InputReader in,PrintWriter out) {
int n = in.nextInt();
int []a = new int[N+10];
long []pre = new long[N+10];
long []aft = new long[N+10];
int []num = new int[N+10];
for (int i = 1;i <= n;i++) a[i] = in.nextInt();
for (int i = 1;i <= n;i++) pre[i] = pre[i-1]+a[i];
for (int i = n;i >= 1;i--) aft[i] = aft[i+1]+a[i];
Hashtable<Long, Integer> dic = new Hashtable<Long,Integer>();
for (int i = n;i >= 1;i--) {
if (aft[i]%2==0) {
long temp = aft[i]/2;
if (dic.get(temp)!=null)
num[i] = dic.get(temp);
}
Integer temp1 = dic.get(aft[i]);
if (temp1==null) {
dic.put( aft[i], 1);
}else {
dic.put(aft[i], temp1+1);
}
}
long ans = 0;
for (int i = 1;i <=n;i++) {
long cur = pre[i];
cur = pre[n]-cur;
if (cur!=pre[i]*2) {
continue;
}
ans = ans + num[i+1];
}
out.println(ans);
}
} static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer; public InputReader() {
br = new BufferedReader(new InputStreamReader(System.in));
tokenizer = null;
} public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
} public int nextInt() {
return Integer.parseInt(next());
}
}
}

【Codeforces 466C】Number of Ways的更多相关文章

  1. 【codeforces 235E】 Number Challenge

    http://codeforces.com/problemset/problem/235/E (题目链接) 题意 给出${a,b,c}$,求${\sum_{i=1}^a\sum_{j=1}^b\sum ...

  2. 【CodeForces 660D】Number of Parallelograms(n个点所能组成的最多平行四边形数量)

    You are given n points on a plane. All the points are distinct and no three of them lie on the same ...

  3. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  4. 【codeforces 514A】Chewbaсca and Number

    [题目链接]:http://codeforces.com/contest/514/problem/A [题意] 允许你把每个数字翻转 ->x变成9-x 然后问你能够变成的最小的数字是什么; 不能 ...

  5. 【codeforces 805D】Minimum number of steps

    [题目链接]:http://codeforces.com/contest/805/problem/D [题意] 给你一个字符串; 里面只包括a和b; 让你把里面的"ab"子串全都去 ...

  6. 【codeforces 546D】Soldier and Number Game

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【codeforces 768C】Jon Snow and his Favourite Number

    [题目链接]:http://codeforces.com/contest/768/problem/C [题意] 给你n个数字; 让你每次把这n个数字排序; 然后对奇数位的数字进行异或操作,然后对新生成 ...

  8. 【34.57%】【codeforces 557D】Vitaly and Cycle

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  9. 【47.95%】【codeforces 554C】Kyoya and Colored Balls

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. YTU 2732:3798-Abs Problem

    2732: 3798-Abs Problem 时间限制: 1 Sec  内存限制: 128 MB  Special Judge 提交: 167  解决: 60 题目描述 Alice and Bob i ...

  2. Flume Netcat Source

    1.cd /usr/local2/flume/conf sudo vim netcat.conf # Name the components on this agent a1.sources = r1 ...

  3. E20170916-hm

    sassy   adj. 无礼的; 漂亮的; <非正,美> <贬>粗鲁的; <褒>时髦的; digest vt. 消化; 整理; compressor  n. 压气 ...

  4. ural 1012. K-based Numbers. Version 2(大数dp)

    和1009相同,只是n达到了180位,可以模拟大数加和大数乘,这里用的java中的大数. import java.math.BigInteger; import java.util.Scanner; ...

  5. [Swift通天遁地]六、智能布局-(2)视图对象的尺寸和位置相对约束

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  6. 《Akka应用模式:分布式应用程序设计实践指南》读书笔记9

    性能 这也是一个比较大的问题,因为性能不一定是Akka本身的问题,还可能是你代码写的有问题. 优化的第一步就是找出性能的瓶颈,隔离出应用程序里面比较耗时的部分,然后尝试对其优化,减少需要耗费的时间成本 ...

  7. Windows和Centos下Docker的安装配置

    Windows和Centos下Docker的安装配置 windows环境下的安装(win10) 在Windows系统上需要利用toolbox来安装Docker,现在 Docker 有专门的 Win10 ...

  8. cocos creator学习

    2019-05-30 22:23:27 按照前一节我发的教程做,大概了解了Cocos creator的基本布局 但是你发现你不好写代码(感觉视频没有提) 需要下载VS code软件,在其上进行编辑,教 ...

  9. HTML--使用下拉列表框,节省空间

    下拉列表在网页中也常会用到,它可以有效的节省网页空间.既可以单选.又可以多选.如下代码: 讲解: 1.value: 2.selected="selected": 设置selecte ...

  10. 350 Intersection of Two Arrays II 两个数组的交集 II

    给定两个数组,写一个方法来计算它们的交集.例如:给定 nums1 = [1, 2, 2, 1], nums2 = [2, 2], 返回 [2, 2].注意:       输出结果中每个元素出现的次数, ...