hdu 6205: card card card输入挂

Posted wy_2016

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hdu 6205: card card card输入挂相关的知识,希望对你有一定的参考价值。

题目链接

感谢 http://blog.csdn.net/txgang/article/details/77568491

 

#include<bits/stdc++.h>
using namespace std;

namespace FastIO
{
    const static int MX=1e6;
    bool IOerror=0;
    char nc()
    {
        static char buf[MX],*p1=buf+MX,*pend=buf+MX;
        if(p1==pend)
        {
            p1=buf;
            pend=buf+fread(buf,1,MX,stdin);
            if(pend==p1)
            {
                IOerror=1;
                return -1;
            }
        }
        return *p1++;
    }
    inline bool blank(char ch)
    {
        return ch== ||ch==\n||ch ==\r||ch ==\t;
    }
    inline int read()    //直接x=read()调用此函数即可,EOF会返回-1
    {
        int x;
        char ch;
        while(blank(ch=nc()));
        if(IOerror) return -1;
        for(x=ch-0;(ch=nc())>=0&&ch<=9;x=x*10+ch-0);//printf("%d===\n",x);
        return x;
    }
}
using namespace FastIO;

const int N=2e6+9;

int a[N],b[N];

int solve(int n)
{
    for(int i=0;i<n;i++) a[i]=read(),a[i+n]=a[i];
    for(int i=0;i<n;i++) b[i]=read(),b[i+n]=b[i];
    int ret=0,fuck=0;
    int sum1=0,sum2=0,be=0;
    for(int i=0;i<2*n&&be<n;i++)
    {
        sum1+=a[i]+b[i];
        sum2+=a[i]-b[i];
        if(sum2<0||i-be+1==n)
        {
            if(sum1>fuck) ret=be,fuck=sum1;
            sum1=sum2=0;
            be=i+1;
        }
    }
    return ret;
}

int main()
{
//    freopen("test.in","r",stdin);
    int n;
    while((n=read())!=-1)
        printf("%d\n",solve(n));
}

 

以上是关于hdu 6205: card card card输入挂的主要内容,如果未能解决你的问题,请参考以下文章

HDU 6205 card card card ( 思维 )

2017ICPC沈阳网络赛 HDU 6025 -- card card card(最大子段和)

HDU4876:ZCC loves cards

HDU 1528 Card Game Cheater

hdu 4336 Card Collector

hdu_4336_Card Collector