problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
acwing::acwing1726类 参考

AcWing 1726. 挤奶顺序 更多...

#include <acwing.h>

静态 Public 成员函数

static int main (istream &cin, ostream &cout)
 

详细描述

AcWing 1726. 挤奶顺序

在文件 acwing.h1075 行定义.

成员函数说明

◆ main()

int acwing::acwing1726::main ( istream &  cin,
ostream &  cout 
)
static

在文件 acwing.cpp3358 行定义.

3358 {
3359 int N;
3360 int M;
3361 int K;
3362 cin >> N >> M >> K;
3363 unordered_set<int> ms;
3364 auto *const m = new int[M];
3365 auto *const n = new int[N + 1];
3366 memset(n, -1, (N + 1) * sizeof(int));
3367 for(int i = 0; i < M; i++) {
3368 cin >> m[i];
3369 ms.insert(m[i]);
3370 }
3371 auto cp = unordered_map<int, int>();
3372 for(int i = 0; i < K; i++) {
3373 int c;
3374 int p;
3375 cin >> c >> p;
3376 n[p] = c;
3377 cp.insert(make_pair(c, p));
3378 }
3379 if(cp.contains(1)) {
3380 //固定
3381 cout << cp[1];
3382 delete[] n;
3383 delete[] m;
3384 return 0;
3385 }
3386 if(ms.contains(1)) {
3387 //在阶级中
3388 int current = 1;
3389 for(int i = 0; i < M; i++) {
3390 //对所有阶级
3391 if(cp.contains(m[i])) {
3392 //是固定的
3393 current = cp[m[i]];
3394 continue;
3395 }
3396 //不是固定的
3397 while(n[current] != -1) {
3398 current++;
3399 }
3400 n[current] = m[i];
3401 if(m[i] == 1) {
3402 cout << current;
3403 delete[] n;
3404 delete[] m;
3405 return 0;
3406 }
3407 }
3408 }
3409 //不在阶级中
3410 int current = N;
3411 for(int i = M - 1; i >= 0; i--) {
3412 if(cp.contains(m[i])) {
3413 //是固定的
3414 current = cp[m[i]];
3415 continue;
3416 }
3417 //不是固定的
3418 while(n[current] != -1) {
3419 current--;
3420 }
3421 n[current] = m[i];
3422 }
3423 for(int i = 1; i <= N; i++) {
3424 if(n[i] == -1) {
3425 cout << i;
3426 break;
3427 }
3428 }
3429 delete[] n;
3430 delete[] m;
3431 return 0;
3432 }
const int N
Definition: acwing.h:146
void ms(vector< int > &arr, int l, int r, int *ans)
Definition: acwing.cpp:6334
const unsigned M
Definition: pat.h:807

引用了 pat::a::a1016::M, acwing::acwing788::ms() , 以及 acwing::acwing2019::N.

被这些函数引用 acwing::TEST().


该类的文档由以下文件生成: