hdu 1146 Ferry loadingIII

//做这道题我知道了按规范行事的重要

#include<iostream>

using namespace std;

int main()

{

    int t,c,n,m,i,time,ln[2],lt[2],ont,bt,temp,llt;

    bool bleft,tleft;

    char ch[10];

    cin>>c;

    while(c--)

    {

        ln[0]=ln[1]=lt[0]=lt[1]=0,bleft=1,ont=0,bt=0;

        cin>>n>>t>>m;

        for(i=0;i<m;i++)

        {

scanf("%d%s",&time,ch);

            if(ch[0]=='l')

                tleft=1;

            else

                tleft=0;

            if(bt+ont<=time)

            {

                bleft=(bleft+ont/t)%2;

                bt=time;

if(bleft==tleft){

                ln[tleft]=0;

                    ont=t;

}

else{

ln[tleft]=1;

                    ont=2*t;

}

                ln[(tleft+1)%2]=0;

lt[0]=lt[1]=0;

printf("%d/n",bt+ont);

            }

            else 

            {

                llt=0;

                if(time>=bt+t){

                    temp=(time-bt)/t;

                    bt+=temp*t;

                    ont-=temp*t;

                    bleft=(bleft+temp)%2;

if(temp%2)//难点

lt[bleft]--;

                    lt[0]-=temp/2;

                    lt[1]-=temp/2;

                    lt[bleft]-=temp%2;

lt[bleft]++;//问题所在

                    if(lt[0]<0){

                        ln[0]=0;

                        lt[0]=0;

                    }

                    if(lt[1]<0)

                    {

                        ln[1]=0;

                        lt[1]=0;

                    }

                }

if(time>bt)

llt=2*t;

                ln[tleft]++;

 

if(bleft==tleft){

                    cout<<bt+2*t*lt[tleft]+t+llt<<endl;

                    if(2*t*lt[tleft]+t+llt>ont)

                        ont=2*t*lt[tleft]+t+llt;

}

else{

                    cout<<bt+2*t+2*t*lt[tleft]<<endl;

if(2*t*lt[tleft]+2*t>ont)

                        ont=2*t*lt[tleft]+2*t;

                }

                if(ln[tleft]==n){

                    ln[tleft]=0;

                    lt[tleft]++;

                }

            }

        }

if(c)

printf("/n");

    }

    return 0;

}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值