2 条题解

  • 0
    @ 2024-11-11 17:08:57

    方法二满分:

    //方法2:
    #include <bits/stdc++.h>
    using namespace std;
    int n, m, x, num;
    bool v[1500200];
    priority_queue<pair<int, int> > q, p;
    
    int main() {
        scanf("%d", &n);
        memset(v,false,sizeof(v));
        for(int i = 1; i <= n; i ++) {
            scanf("%d", &m);
            for(int j = 1; j <= m; j ++) {
                scanf("%d", &x);
                q.push(make_pair(x, ++ num)), p.push(make_pair(-x, num));
            }
            while(v[q.top().second]) q.pop();
            v[q.top().second] = 1;
            while(v[p.top().second]) p.pop();
            v[p.top().second] = 1;
            printf("%d %d\n", -p.top().first, q.top().first);
            q.pop(), p.pop();
        }
        return 0; 
    }
    
    
    • 0
      @ 2024-11-11 17:08:29

      方法一:

      #include <bits/stdc++.h>
      using namespace std;
      
      multiset<int> st;  //定义int类型的set
      int main() {
          int n;
          cin >> n;
          st.clear();
          for (int i = 1; i <= n; i++) {
              int m;
              cin >> m;
              for (int j = 1; j <= m; j++) {
                  int a;
                  cin >> a;
                  st.insert(a);  //插入元素
              }
              cout << *st.begin() << " ";     //输出最小元素
              st.erase(st.begin());           //删除set中最小元素
              cout << *(--st.end()) << endl;  //输出最大元素
              st.erase(--st.end());           //删除set中最大元素
          }
          return 0;
      }
      
      
      • 1

      信息

      ID
      850
      时间
      1000ms
      内存
      256MiB
      难度
      10
      标签
      递交数
      2
      已通过
      1
      上传者