您的位置:首页 > 其它

Sicily 1796. Max's kingdom

2012-02-09 12:21 369 查看
看着数据又大又多,开始还觉得比较麻烦,但一看到4sec的限制,问题就变得简单了:快速排序。注意下怎样储存数据就OK了。

Run Time: 0.49sec

Run Memory: 5524KB

Code length: 815Bytes

SubmitTime: 2011-12-17 19:27:29

// Problem#: 1796
// Submission#: 1088572
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/ // All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int main()
{
int n, p, a;
int sum, mid;
int i;
map<int, vector<int> >::iterator mit;

while ( scanf( "%d", &n ) != EOF ) {
map<int, vector<int> > m;
for ( i = 1; i <= n; i++ ) {
scanf( "%d%d", &p, &a );
m[ p ].push_back( a );
}

for ( mit = m.begin(); mit != m.end(); mit++ ) {
sort( mit->second.begin(), mit->second.end() );
sum = mit->second.size();
if ( sum % 2 == 0 )
mid = ( mit->second[ sum / 2 - 1 ] + mit->second[ sum / 2 ] ) / 2;
else
mid = mit->second[ ( sum - 1 ) / 2 ];
printf( "%d %d\n", mit->first, mid );
}
}

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: