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 ZHOUZUHAO at 2023-03-26 20:31:22 on Problem 1089
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
using namespace std;
int n,num=1;
const int maxn=50005;
typedef pair<int,int> pii;
pii date[maxn],ans[maxn];
bool cmp(pii a,pii b){
	if(a.first!=b.first) return a.first<b.first;
	else return a.second<b.second;
}
void solve(){
	sort(date+1,date+1+n,cmp);
	int nowl,nowr,nextl,nextr;
	nowl=date[1].first,nowr=date[1].second;
	ans[num].first=nowl,ans[num].second=nowr;
	for(int i=2;i<=n;i++){
		nextl=date[i].first,nextr=date[i].second;
		if(nowr<nextl){
			num++;
			nowl=nextl,nowr=nextr;
			ans[num].first=nowl,ans[num].second=nowr;
		}
		else{
			nowr=max(nowr,nextr);
			ans[num].second=nowr;
		}
	}
	for(int i=1;i<=num;i++) cout<<ans[i].first<<" "<<ans[i].second<<'\n';
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=n;i++) 
	cin>>date[i].first>>date[i].second;
	solve();
	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