优先队列40分dalao求debug
查看原帖
优先队列40分dalao求debug
586417
Bz_nnn楼主2023/4/2 12:07

优先队列40分dalao求debug

#include<bits/stdc++.h>
using namespace std;
int s[5] = {}, t[5][25], ans = 0;
priority_queue<int, vector<int>, less<int> >q[5];
void debug(int n){
	while(!q[n].empty()) printf("%d ", q[n].top()), q[n].pop();
}
void dfs(int n){
	if(q[n].top()){
		int x = q[n].top(); q[n].pop();
		int y = q[n].top(); q[n].pop();
		q[n].push(x-1), q[n].push(y-1);
		++ans, dfs(n);
	}
}
int main(){
	for(int i = 1; i <= 4; i++) scanf("%d", &s[i]);
	for(int i = 1; i <= 4; i++){
		for(int j = 1; j <= s[i]; j++){
			scanf("%d", &t[i][j]);
			q[i].push(t[i][j]);
		}
	}
	for(int i = 1; i <= 4; i++) dfs(i);
	printf("%d", ans);
	return 0;
}
2023/4/2 12:07
加载中...