3 solutions

  • 0
    @ 2026-10-25 14:11:51
    21240
    
    
    • 0
      @ 2026-10-25 14:11:29
      100
      0 85 6
      1 61 35
      0 117 44
      0 114 45
      0 182 47
      1 19 48
      1 52 49
      0 265 838
      1 408 866
      0 946 867
      1 86 872
      1 231 875
      1 324 879
      1 357 880
      1 276 882
      0 63 916
      0 357 921
      1 24 936
      0 221 938
      1 102 942
      1 81 949
      0 226 1555
      0 399 1876
      0 237 1907
      0 157 1917
      1 234 1919
      0 183 2820
      1 172 2841
      0 618 2847
      1 158 2848
      1 106 2849
      1 80 2851
      1 122 2852
      1 7 2853
      1 328 2854
      1 5 2855
      1 152 2856
      1 273 2857
      1 129 2858
      1 249 2859
      1 333 2860
      0 828 2861
      1 64 2862
      1 217 2863
      1 269 2864
      0 391 2888
      0 380 3319
      1 386 3332
      1 620 3334
      0 333 3341
      0 300 3365
      1 339 3373
      0 624 3374
      1 546 3375
      1 420 3376
      1 168 3377
      1 319 3378
      0 819 3379
      1 509 3380
      1 453 3381
      1 54 3382
      0 89 3383
      1 336 3384
      1 83 3385
      0 85 4260
      1 156 4293
      1 2 4294
      1 22 4298
      1 126 4299
      1 67 4300
      1 63 4301
      1 72 4302
      1 87 4303
      0 633 4304
      0 150 4336
      1 132 4367
      0 248 4368
      0 624 4369
      0 666 4370
      1 212 4371
      1 49 4372
      1 245 4373
      1 155 4374
      1 239 4375
      1 194 4376
      1 255 4377
      1 120 4378
      1 63 4379
      1 158 4380
      0 62 4716
      1 73 4734
      0 834 4744
      1 19 4751
      0 570 4754
      1 6 4756
      0 652 4757
      1 49 4758
      1 44 4759
      1 79 4760
      0 345 4798
      
      
      • -1
        @ 2024-6-13 17:35:59

        模拟(O(n2)O(n^2) 30pts)

        • 依次枚举每张票,如果是地铁直接购买且存下来,否则就判断能否在以前的地铁里面找到一张可以用的。
        #include<bits/stdc++.h>
        using namespace std;
        const int N=100010;
        struct Node{ 
            int p,t; //票钱,时间
            bool flag; //是否使用
        };
        int main()
        {
            int n;
            cin>>n;
            vector<Node> q;
            int res=0;
            for(int i=1;i<=n;i++)
            {
                int k;
                cin>>k;
                if(k==0) //地铁必须给钱
                {
                    int p,t;
                    cin>>p>>t;
                    res+=p;
                    q.push_back({p,t,0});
                  
                }
                else
                {
                    int p,t;
                    cin>>p>>t; //获取公交的价格
                   
                    for(int i=0;i<q.size();i++)
                    {
                        if(q[i].flag==0&&q[i].p>=p&&t-q[i].t<=45) //找到了一张可以用的
                        {
                            q[i].flag=true; //标记地铁票已经用过了
                            p=0; //公交免费
                            break;
                        }
                    }
                    res+=p;
                }
            }
            cout<<res;
            return 0;
        }
        

        模拟(O(n)O(n) 100pts)

        • 可以使用队列只储存45分钟以内的有效票
        #include<bits/stdc++.h>
        using namespace std;
        const int N=100010;
        struct Node{ 
            int p,t; //票钱,时间
            bool flag; //是否使用
        }q[N];
        int main()
        {
            int n;
            cin>>n;
            int hh=0,tt=-1;
            int res=0;
            for(int i=1;i<=n;i++)
            {
                int k;
                cin>>k;
                if(k==0) //地铁必须给钱
                {
                    int p,t;
                    cin>>p>>t;
                    res+=p;
                    q[++tt]={p,t,0};
                }
                else
                {
                    int p,t;
                    cin>>p>>t; //获取公交的价格
                    while(hh<=tt&&t-q[hh].t>45) hh++; //删除过期的票
                    for(int i=hh;i<=tt;i++)
                    {
                        if(q[i].flag==0&&q[i].p>=p) //找到了一张可以用的
                        {
                            q[i].flag=true; //标记地铁票已经用过了
                            p=0; //公交免费
                            break;
                        }
                    }
                    res+=p;
                }
            }
            cout<<res;
            return 0;
        }
        
        • 1

        Information

        ID
        1064
        Time
        1000ms
        Memory
        256MiB
        Difficulty
        9
        Tags
        # Submissions
        18
        Accepted
        3
        Uploaded By