5 条题解
-
2
方法1
#iclude<bits/stdc++.h> using namespace std; deque<int> a; int n,m,x,cnt,f; int main(){ cin >> m >> n; for(int i=1; i<=n; i++){ cin >> x; f=0; for(auto it:a){ if(it==x){ f=1; }guage if(!f){ cnt++; if(a.size()<m){ a.push_back(x); } else{ a.push_back(x); a.pop_front(); } } } cout << cnt; return 0; }方法2
#include<bits/stdc++.h> using namespace std; int n,m,a[1005],b[1005],len,x,ans; int main (){ cin >> m >> n; while(n--){ cin >> x; if(a[x]==0){ ans++; a[x]=1; if(len<m){ b[++len]=x; } else{ a[b[1]]=0; for(int i=2;i<=m;i++{ b[i-1]=b[i]; } b[m]=x; } } } cout << ans; return 0; } -
0
点赞
#include<bits/stdc++.h> using namespace std; int n,m,a[1005],b[1005],len,x,ans; int main () { cin >> m >> n; while(n--){ cin >> x; if(a[x]==0){ ans++; a[x]=1; if(len<m){ b[++len]=x; } else{ a[b[1]]=0; for(int i=2;i<=m;i++){ b[i-1]=b[i]; } b[m]=x; } } } cout << ans; return 0; } -
-1
包对的
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;-
int main() { int n[10005], ans = 0, i = 1, cnt = 0; char a; while(cin >> n[i] >> a) { ans += n[i++]; cnt++; } for(int i = 1; i <= cnt; i++) { cout << n[i]; if(i != cnt) { cout << "+"; } else { cout << "="; } } cout << ans << endl; return 0; }
-
-1
/***************************************** Note : ******************************************/ #include #include <math.h> #include #include <stdio.h> #include #include <string.h> #include using namespace std; #define LL long long const int N = 1e5 + 10; const int INF = 0x3f3f3f3f; int m,n; bool vis[N]; queue p; int ans = 0; int main() { cin >> m >> n; for(int i = 1 ,x; i <= n ; i++) { cin >> x; if(vis[x]) continue; else { if(p.size() >= m) { vis[p.front()] = false; // 顺序很重要 p.pop(); // 一定要在 " vis[p.front()] = false; " 的后面 } p.push(x); vis[x] = true; ans++; } } cout << ans << endl; return 0; }
- 1
信息
- ID
- 712
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 5
- 标签
- 递交数
- 250
- 已通过
- 95
- 上传者