C - Stripe(注意超时)

来源:互联网 发布:电脑屏幕调节软件 编辑:程序博客网 时间:2024/05/29 17:12
点击打开链接
C - StripeTime Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64uSubmitStatusDescriptionOnce 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?InputThe 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.OutputOutput 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 InputInput91 5 -6 7 9 -16 0 -2 2Output3Input31 1 1Output0Input20 0Output1


2.代码:

#include<stdio.h>int b[100005];int c[100005];int a[100005];int main(){    int n;    scanf("%d",&n);    b[0]=0;    for(int i=1;i<=n;i++)    {        scanf("%d",&a[i]);        b[i]=b[i-1]+a[i];    }    for(int j=n;j>=1;j--)    {        c[j]=c[j+1]+a[j];    }    int ans=0;    for(int i=1;i<n;i++)    {       if(b[i]==c[i+1])       ans++;    }    printf("%d\n",ans);    return 0;}/*91 5 -6 7 9 -16 0 -2 2*/


 

原创粉丝点击