帮忙看看吧P5661 公交换乘
查看原帖
帮忙看看吧P5661 公交换乘
357828
冰箱的主人LR楼主2020/7/7 16:56

P5661 公交换乘

#include<iostream>
#include<cstdio>
using namespace std;
class car {
public:
     int p;
     int time;
     car *next;
};

int main()
{
    int n;
    car *head = new car;
    car *node = head;
        
    int a, b, c, sum(0);
    
        scanf("%d", &n);
        head->next = NULL;
        while (n > 0) {
            scanf("%d %d %d", &a, &b, &c);
            if (a == 0) 
            {
                node->next = new car;
                node = node->next;
                node->p = b;
                node->time = c;
                sum += b;
                node->next = NULL;
            }
            else
            {
                node = head;
                while (node->next != NULL)
                {
                    if ((c - (node->next)->time) > 45)
                    {
                        (*node).next = (*node->next).next;
                    }
                    else
                    {
                        node = node->next;
                    }

                }
                node = head;
                while (node->next != NULL)
                {
                    if ((node->next)->p >= b)
                    {
                        (*node).next = (*node->next).next;
                        if (node->next != NULL)
                            break;
                        else
                            sum -= b;
                    }
                    else
                    {
                        node = node->next;
                    }
                }
                if (node->next == NULL)
                {
                    sum += b;
                }
            }
                --n;
        }
        printf("%d\n", sum);
        sum = 0;
    

}

2020/7/7 16:56
加载中...