这个题一开始没有什么思路,毕竟算法水平基本为0……
看了一位同学的解析之后一下就明白了。按照这个方法,这题很水了。高手的思路真是不一般
将走廊分成200份,有东西走过时,计数器加一。
最后将走过次数最多的地方*10就可以了。
#include <utility>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool rot(pair<int, int> &pr)
{
if(pr.first > pr.second)
swap(pr.first, pr.second);
return true;
}
/*
*将过道分为200份,有东西通过过道时,计数器加一。找出最大的计数器 * 10
*/
int main()
{
freopen("1.txt", "r", stdin);
int n;
cin >> n;
while(n--)
{
int k;
cin >> k;
int a, b;
vector<int> corr(201, 0);
vector<pair<int, int> > vec;
while(k--)
{
cin >> a >> b;
vec.push_back(make_pair(a, b));
}
for_each(vec.begin(), vec.end(), rot);
for(int i = 0; i < vec.size(); ++i)
{
int begin, end;
begin = vec[i].first;
end = vec[i].second;
if(begin % 2 == 0)
begin = begin / 2 - 1;
else
begin /= 2;
if(end % 2 == 0)
end = end / 2 - 1;
else
end /= 2;
for(int j = begin; j <= end; ++j)
{
corr[j]++;
}
}
vector<int>::iterator it = max_element(corr.begin(), corr.end());
cout << (*it) * 10 << endl;
}
}