P5661全WA 求帮
  • 板块学术版
  • 楼主Otisuki
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/9/24 11:49
  • 上次更新2023/11/2 18:21:35
查看原帖
P5661全WA 求帮
763585
Otisuki楼主2023/9/24 11:49
#include<iostream>
using namespace std;
struct info
{
    int tools;  // 0-Subway  1-Bus
    int time;  //0 to time
    int prices;
    bool used;  //  0-Ain't used yet   1-have been used
};
int main()
{
    info points[1000];
    int n; cin>>n;
    int cost=0;
    int subways[1000],latest_ticket=0;
    for(int i=0;i<n;i++)    
    {
        cin>>points[i].tools>> points[i].prices>> points[i].time;  
        points[i].used=false;    //初始化为没用过
        if(points[i].tools==0)  //Taking the subway
        {
            cost+=points[i].prices;  
            subways[latest_ticket]=i;  
            latest_ticket++;  
        }
        else    //Taking the bus
        {
            bool flag=false;   
            for(int j=0;j<latest_ticket;j++)  
            {
                if(subways[j]!=-1)
                {
                    if (points[i].time - points[subways[j]].time <= 45) 
                    {
                        if (!points[subways[j]].used) 
                        {
                            if (points[i].prices <= points[subways[j]].prices) 
                            {
                                cost += 0;
                                //latest_ticket--;
                                subways[j] = -1;
                                flag = true;
                                points[subways[j]].used = true;
                                break;
                            }
                        }
                    }
                }
            }
            if(!flag) cost+=points[i].prices;  //没找到优惠券 加钱
        }
    }
    cout<<cost<<endl;
}
2023/9/24 11:49
加载中...