Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

用优先队列过的渣代码

Posted by DmLeaves at 2020-12-06 16:48:53 on Problem 1089
#include<iostream>
#include<queue>
using namespace std;
struct node {
	int data;
	bool type;
	friend bool operator<(node a, node b)
	{
		if (a.data > b.data) return true;
		else if (a.data == b.data) if (a.type < b.type) return true;
		return false;
	} 
};
int main() {
	ios::sync_with_stdio(false);
	int num;
	while (cin >> num) {
		priority_queue<node, vector<node>> Q;
		node stare = { 0,1 };
		node end = {};
		while (num --)
		{
			cin >> stare.data >> end.data;
			Q.push(stare);
			Q.push(end);
		}
		int count = 0;
		int a;
		while (!Q.empty()) {
			node temp = Q.top();
			Q.pop();
			if (temp.type) {
				if (count == 0) a = temp.data;
				count++;
			}
			else {
				count--;
				if (count == 0) cout << a << " " << temp.data << endl;
			}
		}
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator