Codeforces Beta Round #6 (Div. 2 Only) C. Alice, Bob and Chocolate

來源:互聯網
上載者:User
題目大意

有些長度不同的巧克力棒排成一行,A從左往右吃,B從右往左吃。兩人吃的速度相同,不允許暫停,不允許手中的還沒吃完就吃下一個,當兩個人手中的同時吃完並且下一個要吃的是相同的一個時這個巧克力棒歸A吃。問他們最終都吃了幾個。 解題思路

兩個指標分別從左至右和從右至左。按照題目要求操作即可。 題目代碼

#include <set>#include <map>#include <queue>#include <math.h>#include <vector>#include <string>#include <stdio.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <cctype>#include <algorithm>#include <time.h>#define eps 1e-10#define pi acos(-1.0)#define inf 107374182#define inf64 1152921504606846976#define lc l,m,tr<<1#define rc m + 1,r,tr<<1|1#define zero(a) fabs(a)<eps#define iabs(x)  ((x) > 0 ? (x) : -(x))#define clear1(A, X, SIZE) memset(A, X, sizeof(A[0]) * (min(SIZE,sizeof(A))))#define clearall(A, X) memset(A, X, sizeof(A))#define memcopy1(A , X, SIZE) memcpy(A , X ,sizeof(X[0])*(SIZE))#define memcopyall(A, X) memcpy(A , X ,sizeof(X))#define max( x, y )  ( ((x) > (y)) ? (x) : (y) )#define min( x, y )  ( ((x) < (y)) ? (x) : (y) )using namespace std;int num[100005];int main(){    int l=0,r=0,lp,rp,n;    scanf("%d",&n);    for(int i=0;i<n;i++)    {        scanf("%d",&num[i]);    }    lp=0;    rp=n-1;    while(lp<=rp)    {        if(l<=r)        {            l+=num[lp++];        }        else r+=num[rp--];    }    printf("%d %d",lp,n-rp-1);    return 0;}
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.