Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
水题//#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator