社区讨论
爆TLE求助
P5250【深基17.例5】木材仓库参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @lo2xzh5m
- 此快照首次捕获于
- 2023/10/23 21:37 2 年前
- 此快照最后确认于
- 2023/10/23 21:37 2 年前
你看看我的TLE
我用Map,本地已过
CPP#include <iostream>
#include <map>
using namespace std;
map<int,int> mp;
int type,n;
int Len;
int main()
{
cin>>n;
for(int i=0;i<n;i++)
{
cin>>type;
if(type==1)
{
cin>>Len;
if(mp.count(Len))cout<<"Already Exis\n";
else mp[Len]=Len;
}
else if(type==2)
{
cin>>Len;
if(mp.empty())cout<<"Empty\n";
else if(mp.count(Len)){
cout<<Len<<endl;
mp.erase(Len);
}else if(!mp.count(Len)&&!mp.empty()){
int x=Len,y=Len;
while(1){
x--,y++;
if(mp.count(x)||mp.count(y))
{
if(mp.count(x))
{
cout<<x<<endl;
mp.erase(x);
}else if(mp.count(y))
{
cout<<y<<endl;
mp.erase(y);
}else cout<<x<<endl,mp.erase(x);
break;
}
}
}
}
}
return 0;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...