zoukankan      html  css  js  c++  java
  • Codeforces Beta Round #18 (Div. 2 Only) C. Stripe 前缀和

    C. Stripe

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/problemset/problem/18/C

    Description

    Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, and each piece contains positive integer amount of squares. Would you help Bob solve this problem?

    Input

    The first input line contains integer n (1 ≤ n ≤ 105) — amount of squares in the stripe. The second line contains n space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value.

    Output

    Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only.

    Sample Input

    9
    1 5 -6 7 9 -16 0 -2 2

    Sample Output

    3

    HINT

    题意

    给你n个数,然后说用一个剪刀把这个序列剪开,要求左边等于右边,问总共有多少种剪开的方法

    题解:

    统计一个前缀和就好了……

    代码

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 2000001
    #define mod 1000000007
    #define eps 1e-9
    int Num;
    char CH[20];
    const int inf=0x3f3f3f3f;
    inline ll read()
    {
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    
    //**************************************************************************************
    
    int n;
    int a[maxn];
    int sum[maxn];
    
    int main()
    {
        int n=read();
        for(int i=1;i<=n;i++)
            a[i]=read(),sum[i]=a[i]+sum[i-1];
        int ans=0;
        for(int i=1;i<=n-1;i++)
        {
            if(sum[i]==sum[n]-sum[i])
                ans++;
        }
        cout<<ans<<endl;
    }
  • 相关阅读:
    优化不易,且写且珍惜
    作为过来人的感悟:进了小公司的程序员如何翻身进入大公司
    腾讯/阿里/百度 BAT人才体系的职位层级、薪酬、晋升标准
    校招生向京东发起的“攻势”,做到他这样,你,也可以
    通过Java 线程堆栈进行性能瓶颈分析
    基于Spring Cloud的微服务落地
    多线程技术使用指南
    Android 处理含有EditText的Activity虚拟键盘
    Android ListView的监听事件
    Android 开源框架Universal-Image-Loader完全解析(一)--- 基本介绍及使用
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4601552.html
Copyright © 2011-2022 走看看