hdu 4585 shaolin—— STL lower_bound的应用
2014-03-26 22:51
369 查看
题目链接 点击打开链接
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<cmath> #include<algorithm> #include<iomanip> #include<stdlib.h> #include<set> #include<map> #include<queue> using namespace std; int main() { int n,i; while(scanf("%d",&n)&&n!=0) { int resulta[100005],resultb[100005]; map<int,int> m; map<int,int> ::iterator it; m[1000000000]=1; for(i=0; i<n; i++) { int id; int grade; scanf("%d%d",&id,&grade); resulta[i]=id; it=m.lower_bound(grade); if(it==m.end()) { it--; resultb[i]=it->second; } else if(it==m.begin()) { resultb[i]=it->second; } else { int Maxgrade=it->first; int Maxid=it->second; it--; int Mingrade=it->first; int Minid=it->second; if(grade-Mingrade<=Maxgrade-grade) { resultb[i]=Minid; } else resultb[i]=Maxid; } m[grade]=id; } for(i=0; i<n; i++) { printf("%d %d\n",resulta[i],resultb[i]); } } return 0; }
相关文章推荐
- HDU 4585(Shaolin-Treap的lower_bound&upper_bound操作)
- [HDU 4585] Shaolin (map应用)
- ZOJ3768 夹逼查找【STL__lower_bound()_的应用】
- HDU 4585 Shaolin (STL)
- hdu--4585--lower_bound()
- HDU 4585 Shaolin(水题,STL)
- HDU 4585 Shaolin (STL)
- 【STL】hdu 4585 Shaolin
- HDU 4585 Shaolin (STL)
- STL源码学习----lower_bound和upper_bound算法
- stl中的upper_bound和lower_bound
- STL源码学习----lower_bound和upper_bound算法
- HDU 5246 超级赛亚ACMer (lower_bound 与 upper_bound)
- STL源码学习----lower_bound和upper_bound算法
- HDU 4585 Shaolin (map)
- hdu-4585-Shaolin 平衡二叉树
- STL之lower_bound和upper_bound
- STL源码学习----lower_bound和upper_bound算法
- HDU 4585 Shaolin(听说兼职和尚100+/天)
- HDU 4585 Shaolin STL map 水