Number of Ways--CodeForces 466C 水题

题意:输入一组数,将其割成三段,每一段的值相同

解法:因为要割三组值相同,所以每一组的值一定是整体求和的1/3

千万记得long long,血的代价

#include <stdio.h>
#include <string.h>
long long num[500005];
int main()
{
    int n;
    long long a;
    int i,j;
    long long all;
    while(scanf("%d",&n)!=-1)
    {
        all=0;
        memset(num,0,sizeof(num));
        for(i=0;i<n;i++)
        {
            scanf("%I64d",&a);
            num[i]=num[i-1]+a;
        }
        if(num[n-1]%3!=0)
        {
            printf("0\n");
            continue;
        }
        long long temp=num[n-1]/3;
        a=0;
        for(i=n-2;i>=0;i--)
        {
            if(num[i]==temp)
                all+=a;
            if(num[i]==(2*temp))
                a++;
        }
        printf("%I64d\n",all);
    }
    return 0;
}
时间: 2024-11-29 02:06:40

Number of Ways--CodeForces 466C 水题的相关文章

Pearls in a Row CodeForces 620C 水题

题目:http://codeforces.com/problemset/problem/620/C 文章末有一些测试数据仅供参考 题目大意:就是给你一个数字串,然后将分成几个部分,要求每个部分中必须有一对儿相等的数字,每个数字都属于某个部分,输出划分的部分数量以及对应区间. 很简单一道题,输入的数据都不用存的,输入一个检测一个就好了,用map打标记,用容器存一下要输出的区间端点值,最后挨个儿输出就好了 代码如下: #include<iostream> #include<map> #

Army Creation CodeForces - 813E (水题)

题意: 给定序列, 每次询问一个区间[l,r], 问[l,r]中最多能选多少个数且每种数字不超过k 相当于加强版 HH的项链, 对于一个数t, 主席树维护上k次出现的位置pre[t], 每次查询相当于求区间内pre<左端点的总数 #include <iostream> #include <queue> #define REP(i,a,n) for(int i=a;i<=n;++i) #define mid ((l+r)>>1) using namespace

[CodeForces 466C] Number of Ways

Given an array that has n integers, count the number of ways to split all elements of this array into 3 contiguous parts so that the sum of each part is the same. Each part must not be empty. Algorithm: O(N) runtime 1. If total sum % 3 != 0, return 0

codeforces 505B Mr. Kitayuta&#39;s Colorful Graph(水题)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Mr. Kitayuta's Colorful Graph Mr. Kitayuta has just bought an undirected graph consisting of n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge

CodeForces 444C. DZY Loves Physics(枚举+水题)

转载请注明出处:http://blog.csdn.net/u012860063/article/details/37509207 题目链接:http://codeforces.com/contest/445/problem/C DZY Loves Physics DZY loves Physics, and he enjoys calculating density. Almost everything has density, even a graph. We define the densi

Codeforces Round #113 (Div. 2)E---Tetrahedron(矩阵,水题)

You are given a tetrahedron. Let's mark its vertices with letters A, B, C and D correspondingly. An ant is standing in the vertex D of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one

HDU 4006 The kth great number (基本算法-水题)

The kth great number Problem Description Xiao Ming and Xiao Bao are playing a simple Numbers game. In a round Xiao Ming can choose to write down a number, or ask Xiao Bao what the kth great number is. Because the number written by Xiao Ming is too mu

codeforces Gym 100187L L. Ministry of Truth 水题

L. Ministry of Truth Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/K Description Andrey works in the Ministry of Truth. His work is changing articles in newspapers and magazines so that they praise the Party an

水题 Codeforces Round #303 (Div. 2) A. Toy Cars

题目传送门 1 /* 2 题意:5种情况对应对应第i或j辆车翻了没 3 水题:其实就看对角线的上半边就可以了,vis判断,可惜WA了一次 4 3: if both cars turned over during the collision. 5 是指i,j两辆车,而不是全部 6 */ 7 #include <cstdio> 8 #include <algorithm> 9 #include <cstring> 10 #include <cmath> 11 #