Extraordinarily Tired Students UVA - 12108

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/leekerian/article/details/84536181

简单模拟特别困的学生,此刻我也挺困的昨晚写到1点多没过早上起来看了一下代码发现一个地方写错了,果然太晚的话自己的脑子思考的很差啊,

我是这样的做的弄一个结构体,里面存睡觉时间,清醒时间,状态(0是清醒,1是睡觉)时间(t1表示还能清醒几分钟,t2表示还能睡几分钟)只要对时间做减然后特判时间为0的时候就可以

#include <iostream>

using namespace std;

struct node 
{
    int a,b;
    int c;
    int d;
    int t1;
    int t2;
}st[111];



int main()
{
    int n;
    int fg3=1;
    while(cin>>n&&n!=0)
    {
        for(int i=0;i<n;i++)
        {
            cin>>st[i].a>>st[i].b>>st[i].c;
            int cont=st[i].c%(st[i].a+st[i].b);
            if(cont==0)
            {
                st[i].d=1;
                st[i].t1=0;
                st[i].t2=1;
            }
            else
            {
                if(cont>st[i].a)
                {
                    st[i].d=1;
                    st[i].t1=0;
                    st[i].t2=(st[i].a+st[i].b)-cont+1;
                }
                else
                {
                    st[i].d=0;
                    st[i].t2=0;
                    st[i].t1=st[i].a-cont+1;
                }
                    
            }
        }
        int i;
        int fg1=0;
        for(i=1;i<100000;i++)
        {
            int fg0=0;
            int a=0;
            int b=0;
            for(int j=0;j<n;j++)
            {
                if(st[j].d==0)
                    a++;
                else
                    b++;
            }
            if(a==n)
            {
                fg1=1;
                break;
            }
            for(int j=0;j<n;j++)
            {
                if(st[j].d==0)
                {
                    if(st[j].t1==0)
                    {
                        if(a>=b)
                        {
                            st[j].d=0;
                            st[j].t1=st[j].a;
                            //st[j].t1--;
                        }
                        else
                        {
                            st[j].d=1;
                            st[j].t2=st[j].b;
                            st[j].t2--;
                        }
                    }
                    else
                        st[j].t1--;
                }
                else
                {
                    if(st[j].t2==0)
                    {
                        st[j].d=0;
                        st[j].t1=st[j].a;
                        st[j].t1--;
                    }
                    else
                        st[j].t2--;
                }
            }
        }
        printf("Case %d: ",fg3++);
        if(!fg1)
            cout<<-1<<endl;
        else
            cout<<i-1<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/leekerian/article/details/84536181