HDU4302(map的用法)
来源:互联网 发布:python字典转换为列表 编辑:程序博客网 时间:2024/06/05 20:52
题目:Holedox Eating
#include <iostream>#include <cstring>#include <algorithm>#include <cstdio>#include <map>using namespace std;const int oo=1000000;int main(){ map<int,int>mymap; int t,l,n,co,a,b,ca=0; map<int,int>::iterator it1,it2; scanf("%d",&t); while(t--) { mymap.clear(); mymap[oo]=1,mymap[-oo]=1; scanf("%d%d",&l,&n); co=0; int ans=0,dir; while(n--) { scanf("%d",&a); if(a) { it1=mymap.lower_bound(co); if(it1->first==co) { it1->second--; if(it1->second==0) mymap.erase(it1); } else { it1--; it2=mymap.upper_bound(co); if(it1->first==-oo&&it2->first==oo) continue; if(co-it1->first==it2->first-co) { if(dir==1) { it2->second--; ans+=it2->first-co; co=it2->first; if(it2->second==0) mymap.erase(it2); } else { it1->second--; ans+=co-it1->first; co=it1->first; if(it1->second==0) mymap.erase(it1); } } else if(it2->first-co<co-it1->first) { dir=1; ans+=it2->first-co; co=it2->first; it2->second--; if(it2->second==0) mymap.erase(it2); } else { dir=0; ans+=co-it1->first; co=it1->first; it1->second--; if(it1->second==0) mymap.erase(it1); } } } else { scanf("%d",&b); mymap[b]++; } } printf("Case %d: %d\n",++ca,ans); } return 0;}
- HDU4302(map的用法)
- hdu4302
- 关于map的用法
- map的用法
- STL的map用法
- STL的map用法
- STL的map用法
- map的用法
- map 的用法
- map的用法
- map的用法
- Map.EntrySet的用法
- Map的用法详解
- Map.EntrySet的用法
- Java Map的用法
- std::map的用法
- map的用法
- c++map的用法
- mac 不支持ntfs的写
- [精通WindowsSocket网络开发-基于VC++实现]第三章——WindowsSockets基础—概念
- 控制文件恢复与备份
- 自定义的精简版String类,重载了各种字符串的运算符操作
- 组件为什么需要注册?
- HDU4302(map的用法)
- 三种线性排序算法 计数排序、桶排序与基数排序
- 死锁的形成场景与死锁提示时机分析
- VC获取当前文件路径---比较
- Block编程值得注意的那些事儿
- SQL数据类型
- C语言第十二堂作业
- java输入输出流,字节流,字符流
- warning LNK4098: defaultlib "MSVCRT" conflicts with use of other libs; use /NODEFAULTLIB:library