10 条题解

  • 31
    @ 2023-6-10 0:17:15

    题解两三条,细节提一条 若是没有赞,作者两行泪!!!

    #include <iostream>
    #include <stdio.h>
    #include <algorithm>
    using namespace std;
    int n,m,x,ans,l,r,a[1005],b[1005];
    int main()
    {
        cin>>m>>n;
        l=0;r=0;
        for (int i=1;i<=n;i++)
         {
             while(1){cout<<"你居然抄题解!!!!“<<endl;
             scanf("%d",&x);
             if (a[x]==0) 
             {
                 ans++;
                r++;b[r]=x;a[x]=1;
                if (r>m) {l++;a[b[l]]=0;}
             }
         }
        cout<<ans;
        return 0V0;
    }
    
    • @ 2023-9-22 20:14:16

      、、、cpp

      #include <iostream> #include <stdio.h> #include <algorithm> using namespace std; int n,m,x,ans,l,r,a[1005],b[1005]; int main() { cin>>m>>n; l=0;r=0; for (int i=1;i<=n;i++) { while(1){cout<<"你居然抄题解!!!!“<<endl; scanf("%d",&x); if (a[x]==0) { ans++; r++;b[r]=x;a[x]=1; if (r>m) {l++;a[b[l]]=0;} } } cout<<ans; return 0V0; }

      、、、

    • @ 2023-10-14 16:11:55
      while(1){cout<<"你居然抄题解!!!!“<<endl;
      你这...
      
    • @ 2023-12-10 13:00:32
      while(1){cout<<"你居然抄题解!!!!“<<endl;
      
      return 0V0;
      

      额。。。

    • @ 2024-3-9 9:32:32
      while(1){cout<<"你居然抄题解!!!!“<<endl;
      

      return 0V0
      

    • @ 2024-5-19 16:16:47

      hhhh哈哈哈哈 萌新说:为什么全错啊?:《@

  • 9
    @ 2023-6-10 21:35:57
    #include <bits/stdc++.h>
    using namespace std;
    const int MAXN = 1123;
    int m, n, q[MAXN], h, t, ans;
    bool inq[MAXN];
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cin >> m >> n;
        while (n--) {
            int x;
            cin >> x;
            if (!inq[x]) {
                q[t++] = x;
                inq[x] = true;
                if (t - h > m) {
                    inq[q[h++]] = false;
                }
                ans++;
            }
        }
        cout << ans;
        return 0;
    }
    
    
    • 6
      @ 2024-1-24 9:12:14
      #include <bits/stdc++.h>
      using namespace std;
      queue<int> q;//我超前用了一点,这样会轻松一点。。。。。。
      bool a[1005];//标记该单词是否在内存中
      int main()
      {
      int n,m;
      int ans = 0;
      cin >> m >> n;
      int x;
      for (int i = 1;i <= n;i++)
      {
      cin >> x;
      if (int(q.size())< m)//这里不强制转换一下会有提示,但也可以AC
      {
      if (a[x] == 1)//这里和下面的该语句可以放在if外面,cin之后直接判断
      {
      continue;//接上:因为写的时候忘了,所以也不想改了,反正都能过
      }
      else
      {
      ans++;
      q.push(x);
      a[x] = 1;
      }
      }//如果字典没满
      else//如果字典满了
      {
      if (a[x] == 1)
      {
      continue;
      }
      else
      {
      ans++;
      a[q.front()] = 0;
      q.pop();//先把最前一个删掉,并设置为没有该词
      q.push(x);
      a[x] = 1;//把词加入内存
      }
      }
      }
      cout << ans;//输出查字典的次数即可
      return 0;
      }//勿要抄袭,切记
      //by hetao4582353
      //If you are a good person,please do not copy it.
      //No pain,no gain.别忘点赞
      
      • @ 2024-2-11 14:23:13

        大哥,不加空格真的很难受……

        #include <iostream>
        #include <algorithm>
        #include <cmath>
        #include <queue>
        using namespace std;
        queue<int> q;//我超前用了一点,这样会轻松一点。。。。。。
        bool a[1005];//标记该单词是否在内存中
        int main()
        {
            int n,m;
            int ans = 0;
            cin >> m >> n;
            int x;
            for (int i = 1;i <= n;i++)
            {
                cin >> x;
                if (int(q.size())< m)//这里不强制转换一下会有提示,但也可以AC
                {
                    if (a[x] == 1)//这里和下面的该语句可以放在if外面,cin之后直接判断
                    {
                        continue;//接上:因为写的时候忘了,所以也不想改了,反正都能过
                    }
                    else
                    {
                        ans++;
                        q.push(x);
                        a[x] = 1;
                    }
                }//如果字典没满
                else//如果字典满了
                {
                    if (a[x] == 1)
                    {
                        continue;
                    }
                    else
                    {
                        ans++;
                        a[q.front()] = 0;
                        q.pop();//先把最前一个删掉,并设置为没有该词
                        q.push(x);
                        a[x] = 1;//把词加入内存
                    }
                }
            }
            cout << ans;//输出查字典的次数即可
            return 0;
        }
        
      • @ 2024-5-19 16:18:02

        我也是这样,格式和空格都必须完美 强迫症

    • 3
      @ 2024-3-9 18:58:24
      可以使用vector存储单词
      所以查找便可以用二分查找
      #include <bits/stdc++.h>
      using namespace std;
      int n,m,x,ans;
      vector<int>v;
      bool check(vector<int>v1,int x1){
          int l=0,r=v1.size()-1,mid;
          sort(v1.begin(),v1.end());
          while (l<=r){
              mid=(r+l)/2;
              if (v1[mid]==x1)return 0;
              if (v1[mid]>x1)r=mid-1;
              else l=mid+1;
          }
          return 1;
      }
      int main(){
          cin>>m>>n;
          for (int i=1;i<=n;i++){
              cin>>x;
              if (check(v,x)){
                  v.push_back(x);
                  ans++;
              }
              if ((int)v.size()>m)v.erase(v.begin());
          }
          cout<<ans;
          return 0;
      }
      
      • 2
        @ 2023-3-14 18:24:23

        本题使用队列来模拟即可,由于需要判断新当前单词是否已经在内存中,因此需要用一个数组inq来标记每个数字是否在队列里面。

        代码
        
        #include <bits/stdc++.h>
        using namespace std;
        const int MAXN = 1123;
        int m, n, q[MAXN], h, t, ans;
        bool inq[MAXN];
        int main()
        {
            ios::sync_with_stdio(false);
            cin.tie(0);
            cout.tie(0);
            cin >> m >> n;
            while (n--) {
                int x;
                cin >> x;
                if (!inq[x]) {
                    q[t++] = x;
                    inq[x] = true;
                    if (t - h > m) {
                        inq[q[h++]] = false;
                    }
                    ans++;
                }
            }
            cout << ans;
            return 0;
        }
        
        • @ 2023-10-13 20:04:07

          好奇宝宝问一下:那个三角怎么做的啊

        • @ 2023-12-23 18:39:53

          @

          <details>
          <summary>标题</summary>
          内容(可以嵌套)
          </details>
          
      • 1
        @ 2023-5-26 20:11:16

        按照题意模拟即可

        核心代码:

        while(n--){
                bool find=false;
                scanf("%d",&k);
                for(int i=L;i<R;i++) if(que[i]==k) find=true;
                if(!find) cnt++,que[R++]=k;
                if(R-L>m) L++; 
            }
        

        循环队列

        for(int i = 0;i < n;++i){
                int tmp;
                scanf("%d", &tmp);
                if(hash[tmp])   continue;
                hash[tmp] = 1;
                if(head == tail && i )    hash[zhan[tail]] = 0,tail = (tail + 1) % m;  //删除标记。出队
                zhan[head] = tmp, head = (head + 1) % m;   //入队
        
        • -14
          @ 2023-10-14 21:12:15

          正宗的模拟队列解法。。。 //后的语句建议运行一下,看看效果

          #include<bits/stdc++.h>
          using namespace std;
          int m,n,a[1005],sum;
          int que[100005],head=1,tail;
          bool book(int x){
          //    cout<<head<<'-'<<tail<<' ';
              for (int j=head;j<=tail;j++){
                  if (x==que[j])return 0;
              }
              return 1;
          }
          int main(){
              cin>>m>>n;
              for (int i=1;i<=n;i++)cin>>a[i];
              for (int i=1;i<=n;i++){
          //        for (int j=head;j<=tail;j++)cout<<que[j]<<' ';
                  if (book(a[i])){
                      if (tail-head+1==m)head++;
                      que[++tail]=a[i];
                      sum++;
          //            cout<<a[i]<<'-'<<sum<<endl;
                  }
              }
          //    cout<<endl;
              cout<<sum;
              return 0;
          }
          
        • -16
          @ 2023-12-30 18:10:40
          标题 内容
          • -19
            @ 2024-1-8 19:51:20
            标题 标题 标题 标题 标题 标题 标题 标题 标题 标题 标题 标题 标题 标题 标题 标题 :P
            • -19
              @ 2024-1-8 19:50:07
              标题 标题
              • 1

              信息

              ID
              48
              时间
              1000ms
              内存
              256MiB
              难度
              4
              标签
              (无)
              递交数
              1619
              已通过
              715
              上传者