玄关

P1540 [NOIP2010 提高组] 机器翻译

@[lucy2012](/user/1252442) 需要那么麻烦吗? ```cpp #include<iostream> using namespace std; int ans; struct queue{ int l=1,r=0,a[1010]={};bool h[1010]={};//记录每个数是否出现过 void push(int x){ if(h[x]==0)a[++r]=x,h[x]=1,ans++;//加入元素 }void pop(){ h[a[l]]=0,l++; }int size(){ return r-l+1; } }; int main(){ int n,m,x;cin>>n>>m; queue q; for(int i=1;i<=m;i++){ cin>>x; q.push(x); if(q.size()>n)q.pop(); }cout<<ans; } ```
by xd244 @ 2024-04-27 20:47:13


```cpp #include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 50; int m,n,x,ans = 0; bool w[maxn]; int q[maxn],front = 1,rear = 0; int main(){ memset(w,false,sizeof(w)); scanf("%d%d",&m,&n); for (int i = 1; i <= n; i++) { scanf("%d",&x); if (w[x] == false) { if (rear - front + 1 >= m) w[q[front++]] = false; w[x] = true; q[++rear] = x; ans++; } } printf("%d",ans); return 0; } ``` 找一找
by liuruiqing @ 2024-04-27 22:25:34


毕竟stl太乱了,debug比较麻烦 真的无语了找不到 @[lucy2012](/user/1252442)
by liuruiqing @ 2024-04-27 22:27:24


@[liuruiqing](/user/1118614) 没事,非常感谢啦!
by lucy2012 @ 2024-04-27 22:30:31


|