码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces 21C Stripe 2 卧槽,出题人母语绝对不是English啊

时间:2014-11-06 21:59:33      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   os   for   sp   on   2014   

sum = sigma num[i] (1 <= i <= n)。

s[i] = sigam num[j] (1<= j <= i)。

找到所有满足s[i]*2 =sum-s[i] ,s[i] = 2*(sum-s[i])。然后枚举累加一下。

卧槽,可是题意里明明说每个 piece 里 都要有positive interge。

可是去了这个限制就过了啊。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <ctime>
#include <iomanip>

#pragma comment(linker, "/STACK:1024000000");
#define EPS (1e-6)
#define _LL long long
#define ULL unsigned long long
#define LL __int64
#define INF 0x3f3f3f3f
#define Mod 1000000007

/** I/O Accelerator Interface .. **/
#define g (c=getchar())
#define d isdigit(g)
#define p x=x*10+c-'0'
#define n x=x*10+'0'-c
#define pp l/=10,p
#define nn l/=10,n
template<class T> inline T& RD(T &x)
{
    char c;
    while(!d);
    x=c-'0';
    while(d)p;
    return x;
}
template<class T> inline T& RDD(T &x)
{
    char c;
    while(g,c!='-'&&!isdigit(c));
    if (c=='-')
    {
        x='0'-g;
        while(d)n;
    }
    else
    {
        x=c-'0';
        while(d)p;
    }
    return x;
}
inline double& RF(double &x)      //scanf("%lf", &x);
{
    char c;
    while(g,c!='-'&&c!='.'&&!isdigit(c));
    if(c=='-')if(g=='.')
        {
            x=0;
            double l=1;
            while(d)nn;
            x*=l;
        }
        else
        {
            x='0'-c;
            while(d)n;
            if(c=='.')
            {
                double l=1;
                while(d)nn;
                x*=l;
            }
        }
    else if(c=='.')
    {
        x=0;
        double l=1;
        while(d)pp;
        x*=l;
    }
    else
    {
        x=c-'0';
        while(d)p;
        if(c=='.')
        {
            double l=1;
            while(d)pp;
            x*=l;
        }
    }
    return x;
}
#undef nn
#undef pp
#undef n
#undef p
#undef d
#undef g
using namespace std;

LL num[100010];
LL ans[2][100010] = {{0},{0}};
LL sum[2][100010] = {{0},{0}};
LL dis[100010] = {0};

int mark[2][100010] = {{0},{0}};

int main()
{
    int n;

    scanf("%d",&n);

    int i;

    for(i = 1;i <= n; ++i)
        scanf("%I64d",&num[i]);

    for(i = 1;i <= n; ++i)
        sum[0][i] = sum[0][i-1] + num[i];
    for(i = n;i >= 1; --i)
        sum[1][i] = sum[1][i+1] + num[i];

    for(i = 1;i <= n; ++i)
            ans[0][i] = ans[0][i-1] + (num[i] >= 0 ? 1 : 0);
    for(i = n;i >= 1; --i)
            ans[1][i] = ans[1][i+1] + (num[i] >= 0 ? 1 : 0);

    LL S = sum[0][n];

    for(i = 1;i <= n; ++i)
        if(sum[0][i]*2 == S-sum[0][i] )
            mark[0][i] = 1;
    for(i = n;i >= 1; --i)
        if(sum[1][i]*2 == S-sum[1][i])
            mark[1][i] = 1;
    for(i = 1;i <= n; ++i)
        dis[i] = dis[i-1] + mark[0][i];

    LL anw = 0;

    for(i = 2;i <= n; ++i)
        if(mark[1][i])
            anw += dis[i-2];
    printf("%I64d\n",anw);
    return 0;
}
















Codeforces 21C Stripe 2 卧槽,出题人母语绝对不是English啊

标签:style   blog   io   ar   os   for   sp   on   2014   

原文地址:http://blog.csdn.net/zmx354/article/details/40867085

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!