[悬关]黄题模拟求调
查看原帖
[悬关]黄题模拟求调
781159
Lovely_Elaina楼主2023/3/5 22:34
#include <bits/stdc++.h>
using namespace std;

const int N = 105;
const int M = 2005;

struct node{
    int w;
    int l,r;
}a[M];

int b[N],m,n;
int tol; // 车的总数
int is_b[N];
long long sum;

queue<int > q; // 待入车辆

void print(){
    for(int i = 1; i <= n; i++){
        cout << is_b[i] << " ";
    }cout << endl;
}

void wait();
void enter(int x);
void leave(int x);

void wait(){
    if(tol == n) return ;
    if(q.empty()) return ;
    while(tol < n){
        tol++;
        enter(q.front());
        q.pop();
    }
}

void enter(int x){
    if(tol == n){
        q.push(x);
        return ;
    }
    
    int i = 1;
    while(is_b[i]) i++;
    is_b[i] = x;
    //print();
    sum += (b[i]*a[x].w);
    tol++;
}

void leave(int x){
    int i = 1;
    while(is_b[i] != x) i++;
    is_b[i] = 0;
    tol--;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        cin >> b[i];
    }
    for(int i = 1; i <= m; i++){
        cin >> a[i].w;
    }
    
    int x;
    m *= 2;
    while(m--){
        cin >> x;
        if(x > 0){
            wait();
            enter(x);
        }else{
            wait();
            leave(-x);
        }
        //print();
        //cout << tol << endl;
        //cout << q.empty() << endl;
    }
    
    cout << sum << endl;
    
    return 0;
}

被催睡觉了,先不改了

2023/3/5 22:34
加载中...