HDU 4585 Shaolin (STL)
2013-08-14 14:08
387 查看
没想到map还有排序功能,默认按照键值从小到大排序
#include <cstdio> #include <iostream> #include <cstring> #include <cmath> #include <map> #include <algorithm> #include <cstdlib> using namespace std; int main() { int n; int id,g; while(scanf("%d",&n) && n) { map<int,int>m; m[1000000000] = 1; for(int i=1; i<=n; ++i) { scanf("%d%d",&id,&g); printf("%d ",id); map<int,int> ::iterator it; it = m.lower_bound(g); // 二分找第一个大于等于g的位置,如果没有,则返回末尾位置 if(it == m.end()) { it -- ; printf("%d\n",it->second); } else { if(it == m.begin()) { printf("%d\n",it->second); } else { int pos = it->first; int tmp = it->second; it --; printf("%d\n",(pos - g) < (g - it->first) ? tmp : it->second); } } m[g] = id; } } return 0; }
相关文章推荐
- HDU 4585 Shaolin (STL)
- 【STL】hdu 4585 Shaolin
- HDU 4585 Shaolin (STL)
- hdu 4585 shaolin—— STL lower_bound的应用
- HDU 4585 Shaolin(水题,STL)
- [HDU 4585] Shaolin (map应用)
- HDU 4585 Shaolin(Treap)
- hdu-4585-Shaolin 平衡二叉树
- HDU 4585 Shaolin
- hdu 4585 shaolin 平衡树
- HDU 4585 Shaolin 找最接近的数 Treap / set
- hdu 4585 Shaolin(STL map)
- HDU 4585 Shaolin(听说兼职和尚100+/天)
- HDU 4585 Shaolin (map)
- HDU 4585 Shaolin(STL map)
- HDU 4585 ShaoLin 基础Treap
- HDU 4585——Shaolin
- hdu 4585 Shaolin(二分)
- HDU 4585(Shaolin-Treap的lower_bound&upper_bound操作)
- HDU 4585 Shaolin(2013杭州邀请赛J题-二分)