CSP-J 2019公交换乘题解

#include <iostream>
using namespace std;
int n,f,h,t,ans,price[100005],tm[100005];
struct node
{
    int pr,time;
    bool flag;
}q[100005];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>f>>price[i]>>tm[i];
        if(f==0)
        {
            ans+=price[i];
            t++;
            q[t].pr=price[i];
            q[t].time=tm[i];
            q[t].flag=false;
        }
        else
        {
            int j;
            if(tm[i]>45)
            {
                j=t;
                while(q[j].time+45>tm[i])j--;
                h=j;
            }
            else h=1;
            while(h<=t)
            {
                if(price[i]<=q[h].pr && tm[i]<=q[h].time+45 && q[h].flag==false)
                {
                    q[h].flag=true;
                    break;
                }
                else h++;
            }
            if(h>t)ans+=price[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}
全部评论

相关推荐

不服输的外卷侠很健谈:杭电来我公司还是很有认可度的,可以来试试
点赞 评论 收藏
分享
09-06 12:49
门头沟学院 Java
offeroffer...:我也是,前两面还挺紧张认真的,全程大脑飞速运转后面就越来越不想面了,不想说话不想思考
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务