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

晚餐队列安排

时间:2018-10-26 19:35:53      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:target   lan   lse   队列   http   sub   pac   problem   ++   

 

传送门:https://www.luogu.org/problemnew/show/P2837#sub

#include<cstdio>
#include<algorithm>
using namespace std;
inline int read()
{
    static char ch;
    while((ch = getchar()) < 0 || ch > 9);
    int ret = ch - 48;
    while((ch = getchar()) >= 0 && ch <= 9)
        ret = ret * 10 + ch - 48;
    return ret;
}
int n,a[30010],ans;
struct node
{
    int one,two;
}t[30010];
int main()
{
    n = read();
    for(int i = 1;i <= n;i++)
    {
        a[i] = read();
        if(a[i] == 1)
        {
            t[i].one = t[i-1].one + 1;
            t[i].two = t[i-1].two;
        }
        else
        {
            t[i].two = t[i-1].two + 1;
            t[i].one = t[i-1].one;
        }
    }
    ans = min(t[n].one,t[n].two);
    for(int i = 1;i <= n;i++)
        ans = min(ans,t[n].one - t[i].one + t[i].two);
    printf("%d",ans);
    return 0;
}

 

晚餐队列安排

标签:target   lan   lse   队列   http   sub   pac   problem   ++   

原文地址:https://www.cnblogs.com/peppa/p/9857842.html

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