• 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;
    }
  • 相关阅读:
    ios中静态库的创建和使用、制作通用静态库(Cocoa Touch Static Library)
    ios-字符串替换-正则表达式-例子
    Android 中自定义仪表盘
    Android中控件AutoCompleteTextView的使用方法和一些属性
    用代码如何检测一个android程序是否在运行
    android 报错: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/animation/AnimatorCompatHelper;
    android中Zing二维码扫描,二维码生成
    gps数据上传防止android系统休眠
    Android中判断service是否在运行
    BottomSheetDialogFragment 如何设置高度和禁止滑动
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4601552.html
Copyright © 2020-2023  润新知