EOJ_1015_查字典
生活随笔
收集整理的這篇文章主要介紹了
EOJ_1015_查字典
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#include <bits/stdc++.h>
#define MAX 20004
using namespace std;
//入隊列和出隊是隊列
//查詢操作可以加一個mapint q[MAX]={0};
int head=0;
int tail=0;
map<int, bool> table;int main()
{int m,n;cin>>m>>n;int res=0;for(int i=0;i<n;i++){int tmp;cin>>tmp;if(!table.count(tmp)){//cout<<"tmp*"<<tmp<<endl;if((tail-head)>=m){table.erase(q[head]);//cout<<q[head]<<endl;//cout<<table[q[head]]<<endl;//有這一行則res=4 而不是res=5,以為table[q[head]]會在map中創建一個新keyhead++;}table.insert(make_pair(tmp,true));q[tail]=tmp;tail++;res++;//cout<<tmp<<endl;}}cout<<res<<endl;return 0;
}```
總結
以上是生活随笔為你收集整理的EOJ_1015_查字典的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: EOJ_1021_可旋栈
- 下一篇: EOJ_1017_座位分配