4 条题解

  • 9
    @ 2023-10-28 13:19:51

    蒟蒻用的是贪心,大佬不喜勿碰

    #include <bits/stdc++.h>
    using namespace std;
    int w, ans, a[30005], l, r, n;
    int main()
    {
        cin >> w >> n;
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        sort (a + 1, a + n + 1);
        l = 1, r = n;
        while (l <= r)
        {
            if (a[l] + a[r] <= w)
            {
                l++;
                r--;
                ans++;
            }
            else
            {
                r--;
                ans++;
            }
        }
        cout << ans << endl;
        return 0;
    }
    
    • 3
      @ 2023-10-4 12:18:36
      #include<bits/stdc++.h>
      using namespace std;
      int n,maxx,sum,num,a[100005],l,r;
      int main(){
          cin>>maxx>>n;
          for(int i=0;i<n;i++)cin>>a[i];
          sort(a,a+n);
          r=n-1;
          while(n>0){
              if(a[l]+a[r]>maxx){
                  r--;
                  num++;
                  n--;
              }
              else{
                  r--;
                  l++;
                  num++;
                  n-=2;
              }
          }
          cout<<num;
          return 0;
      } // 已AC
      
      • 3
        @ 2023-6-10 19:02:13

        image

        • 0
          @ 2023-8-14 12:25:29

          #include <bits/stdc++.h> using namespace std; vector<int> qwq[1000010]; int n,m,a,x,y; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> x >> y; qwq[x].push_back(y); } cin >> m; for (int i = 1; i <= m; i++) { cin >> a; int len = qwq[a].size(); if (len == 0) cout << endl; else if (len % 2 == 0) cout<<qwq[a][len/2-1]<<" "<<qwq[a][len/2]<<endl; else cout << qwq[a][len/2] << endl; } return 0; }//已AC

          • 1

          [NOIP2007 普及组] 纪念品分组

          信息

          ID
          1504
          时间
          1000ms
          内存
          256MiB
          难度
          4
          标签
          递交数
          213
          已通过
          102
          上传者