• 洛谷 P5661 公交换乘(队列)


    题目传送门

    解题思路:

    暴力模拟.

    AC代码:

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<queue>
     4 
     5 using namespace std;
     6 
     7 long long n,ans,tot;
     8 bool vis;
     9 struct kkk {
    10     long long ti,v;
    11 }e[100001];
    12 queue<kkk> q,q1;
    13 
    14 int main() {
    15     scanf("%lld",&n);
    16     for(int i = 1;i <= n; i++) {
    17         long long x,y,z;
    18         scanf("%lld%lld%lld",&x,&y,&z);
    19         if(x == 0) {
    20             ans += y;
    21             e[++tot].ti = z + 45;e[tot].v = y;
    22             q.push(e[tot]);
    23         }
    24         if(x == 1) {
    25             vis = 0;
    26             while(!q.empty()) {
    27                 kkk o = q.front();
    28                 if(o.ti < z)
    29                     q.pop();
    30                 else    
    31                     break; 
    32             }
    33             while(!q.empty()) {
    34                 kkk o = q.front();
    35                 if(o.v < y) {
    36                     q1.push(o);
    37                     q.pop();
    38                     continue;
    39                 }
    40                 vis = 1;
    41                 q.pop();
    42                 break;
    43             }
    44             if(!vis) ans += y;
    45             while(!q.empty()) {
    46                 q1.push(q.front());
    47                 q.pop();
    48             }
    49             while(!q1.empty()) {
    50                 q.push(q1.front());
    51                 q1.pop();
    52             }
    53         }
    54     }
    55     printf("%lld",ans);
    56     return 0;
    57 } 

    //CSP-J 2019 T2

  • 相关阅读:
    pinyin4j使用示例
    迭代器模式
    适配器模式
    策略模式
    装饰模式
    责任链模式
    命令模式
    中介者模式
    原型模式
    代理模式
  • 原文地址:https://www.cnblogs.com/lipeiyi520/p/11924938.html
Copyright © 2020-2023  润新知