[Codeforces]6C. Alice, Bob and Chocolate

題目URL:http://codeforces.com/contest/6/problem/C
這題很單純的是用deque去頭尾比總和拔值,並且分別記數


#include<bits/stdc++.h>
using namespace std;
signed main()
{
    deque<int> de;
    int num,a=0,b=0,t,totala=0,totalb=0;
    cin >> num;
    for(int i=0;i<num;i++)
    {
        cin >> t;
        de.push_back(t);
    }
    a+=de.front();
    de.pop_front();
    totala++;
    while(!de.empty())
    {
        //cout << a << " " << b << endl;;
        if(b>=a)
        {
            a+=de.front();
            de.pop_front();
            totala++;
        }
        else
        {
            b+=de.back();
            de.pop_back();
            totalb++;
        }
    }
    cout << totala << " " << totalb <<endl;
    return 0;
}

留言

這個網誌中的熱門文章

[ZJ] b229: TOI 2009 第一題:路徑問題

交大資工(APCS組)(面試&心得)

滿是挫傷的ION CAMP