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
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; }
相关文章推荐
- Sicily 1796. Max's kingdom
- soj 1796. Max's kingdom
- Sicily 1796. Max's kingdom
- sicily 1796. Max's kingdom
- !HDU 1025 Constructing Roads In JGShining's Kingdom--DP--(LIS算法)
- 杭电 1003--Max Sum(初级DP)
- hdu 3530 Subsequence 单调队列 求最长连续区间,满足条件(m<=max-min<=k)
- 3DS&nbsp;Max中bip动画融合及ogre动画导…
- sicily 1898 && 2608 Tree
- hdu 1858 Max Partial Value I(DP…
- MySQL max_allowed_packet设置及问题
- autodesk 3ds max 2012中文版 64位&32位 免费版
- MySql 错误 Err [Imp] 1153 - Got a packet bigger than 'max_allowed_packet' bytes
- sicily 1011. Lenny's Lucky Lotto
- ERROR 1153 (08S01): Got a packet bigger than 'max_allowed_packet' bytes
- acm1003 Max Sum
- MeasureSpec学习—对Integer.MAX_VALUE >> 2的认识
- [sicily online]1011. Lenny's Lucky Lotto
- Sicily 1827 && 1947 Sniper
- MySql 错误 Err [Imp] 1153 - Got a packet bigger than 'max_allowed_packet' bytes