zoukankan      html  css  js  c++  java
  • CF18 C. Stripe

    题目传送门:https://codeforces.com/problemset/problem/18/C

    题目大意:
    给你一串长度为(A)的序列,问有多少种分割方法,使得两段数字和相同


    记前缀和(Pre),记后缀和(Suf),求所有(Pre_i=Suf_{i+1})的点即可

    /*program from Wolfycz*/
    #include<map>
    #include<cmath>
    #include<cstdio>
    #include<vector>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #define Fi first
    #define Se second
    #define ll_inf 1e18
    #define MK make_pair
    #define sqr(x) ((x)*(x))
    #define pii pair<int,int>
    #define int_inf 0x7f7f7f7f
    using namespace std;
    typedef long long ll;
    typedef unsigned int ui;
    typedef unsigned long long ull;
    inline char gc(){
    	static char buf[1000000],*p1=buf,*p2=buf;
    	return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
    }
    template<typename T>inline T frd(T x){
    	int f=1; char ch=gc();
    	for (;ch<'0'||ch>'9';ch=gc())	if (ch=='-')    f=-1;
    	for (;ch>='0'&&ch<='9';ch=gc())	x=(x<<1)+(x<<3)+ch-'0';
    	return x*f;
    }
    template<typename T>inline T read(T x){
    	int f=1; char ch=getchar();
    	for (;ch<'0'||ch>'9';ch=getchar())	if (ch=='-')	f=-1;
    	for (;ch>='0'&&ch<='9';ch=getchar())	x=(x<<1)+(x<<3)+ch-'0';
    	return x*f;
    }
    inline void print(int x){
    	if (x<0)	putchar('-'),x=-x;
    	if (x>9)	print(x/10);
    	putchar(x%10+'0');
    }
    const int N=1e5;
    int Pre[N+10],Suf[N+10],A[N+10];
    int main(){
    //	freopen(".in","r",stdin);
    //	freopen(".out","w",stdout);
    	int n=read(0),Ans=0;
    	for (int i=1;i<=n;i++)	A[i]=read(0);
    	for (int i=1;i<=n;i++)	Pre[i]=Pre[i-1]+A[i];
    	for (int i=n;i>=1;i--)	Suf[i]=Suf[i+1]+A[i];
    	for (int i=1;i<n;i++)	Ans+=(Pre[i]==Suf[i+1]);
    	printf("%d
    ",Ans);
    	return 0;
    }
    
    作者:Wolfycz
    本文版权归作者和博客园共有,欢迎转载,但必须在文章开头注明原文出处,否则保留追究法律责任的权利
  • 相关阅读:
    (转)基于C#的socket编程的TCP异步实现
    socket
    (转)抽象类、抽象属性、抽象方法
    (转)c# 互斥锁
    (转)C#连接OleDBConnection数据库的操作
    c# DLL封装并调用
    网络cmd命令
    (转)UCOSII在任务切换与出入中断时堆栈指针的使用
    app和bootloader跳转 MSP与PSP
    (转)stm32启动文件详解
  • 原文地址:https://www.cnblogs.com/Wolfycz/p/14958533.html
Copyright © 2011-2022 走看看