題目鏈接
西安郵電大學有一輛從老校區到新校區的校車,總共有 n 個學生乘坐校車,在ai站上車,在bi站下車。學校打算去除一部分不必要的站點,請問需要保留多少站點,需要安排多少個座位?
輸入描述:
輸入 T 組數據 ((1≤T≤10)
輸入 n
輸入 n 組 ai bi
輸出描述:
輸出保留站點數,座位數。
示例1
輸入
1
3
1 2
1 3
2 4
輸出
4 2
題解:用個map記錄一下出現了幾個站,然後遍歷加起來一下去最大值。
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+100;
typedef long long ll;
int main()
{
int t,n;
for(cin>>t;t;t--)
{
cin>>n;
map<int,int>mmp;
for(int i=1;i<=n;i++)
{
int a,b;
cin>>a>>b;
mmp[a]++;
mmp[b]--;
}
int ma=0,s=0;
for(auto it:mmp)
{
s+=it.second;
ma=max(ma,s);
}
cout<<mmp.size()<<" "<<ma<<endl;
}
system("pause");
return 0;
}