5 条题解

  • 2
    @ 2025-10-31 19:34:13

    方法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
      @ 2025-10-31 19:41:52

      点赞

      #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
        @ 2025-4-18 17:54:04

        包对的

        #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
          @ 2023-11-1 12:27:50

          #include
          using namespace std;
          int a[1005],b[1005];
          int main(){
          int m,n,len=0,x,ans=0;
          cin>>m>>n;
          while(n--){
          cin>>x;
          if(b[x]==0){
          ans++;
          b[x]=1;
          if(len<m)
          a[++len]=x;
          else{
          b[a[1]]=0;
          for(int i=2;i<=m;i++)
          a[i-1]=a[i];
          a[m]=x;
          }
          }
          }
          cout<<ans;
          }

          • -1
            @ 2022-3-3 22:21:52

            /***************************************** 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
            上传者