CF 6 C. Alice, Bob and Chocolate

题目:Alice, Bob and Chocolate

思路:就是找处于最中间的值,然后特别判断一下

 

#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
int num[100010];
int main()
{
    int n;
    scanf("%d",&n);
    long long sum=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&num[i]);
        sum+=num[i];
    }
    long long total=0;
    int cnt=1;
    for(int i=1;i<=n;i++)
    {
        if(total+num[i]>sum/2)
        {
            cnt=i;
            break;
        }
        total+=num[i];
    }
    long long miao=sum-total-num[cnt];
    if(total>miao)
        cnt--;
    cout<<cnt<<" "<<n-cnt<<endl;
    return 0;
}
View Code

 

posted @ 2013-07-15 16:31  over_flow  阅读(201)  评论(0编辑  收藏  举报