4 条题解

  • 23
    @ 2023-7-23 13:43:31

    很简单的好吧((但是这个屑过了试了两遍才通过啊啊啊

    不管怎么样,先上思路!

    点我解锁思路

    好的,恭喜你迈开了成功的第一步!

    不管怎么说,既然你点开了,我只能摊牌了:很简单,只需要使用 priority_queue就彳亍了~

    (我可真的是太水了哈哈哈哈哈哈哈哈哈

    好的,那么我再氵一次:

    点我解锁代码

    好的!你又迈开了一步!是时候给你我的代码了!!!

    #include <bits/stdc++.h>
    
    using namespace std;
    
    struct Stu {
        int id;
        int ch, ma;
    };
    
    struct cmp {
        bool operator () (Stu x, Stu y) {
            return x.ch + x.ma < y.ch + y.ma;
        }
    };
    
    priority_queue<Stu, vector<Stu>, cmp> pq;
    
    int main() {
        int n;
        cin >> n;
        for (int tool = 0; tool < n; tool++) {
            string s;
            cin >> s;
            if (s == "IN") {
                Stu tmp;
                cin >> tmp.id >> tmp.ch >> tmp.ma;
                pq.push(tmp);
            } else if (s == "MAX") {
                if (!pq.empty()) {
                    cout << pq.top().id << " " << pq.top().ch << " " << pq.top().ma << endl;
                }
            } else if (s == "OUT") {
                if (!pq.empty()) {
                    pq.pop();
                }
            } else if (s == "COUNT") {
                cout << pq.size() << endl;
            }
        } return 0;
    }
    
    

    快去逝逝吧!

    这时陷阱不要点开!

    好的,恭喜你点开了陷阱!

    是时候告诉你了!刚刚的,是10分代码![奸笑]

    那么现在才是

    AC代码
    #include <bits/stdc++.h>
    
    using namespace std;
    
    struct Stu {
        int id;
        int ch, ma, sum;
    };
    
    struct cmp {
        bool operator () (Stu x, Stu y) {
            return x.ch + x.ma < y.ch + y.ma;
        }
    };
    
    priority_queue<Stu, vector<Stu>, cmp> pq;
    
    int main() {
        int n;
        cin >> n;
        for (int tool = 0; tool < n; tool++) {
            string s;
            cin >> s;
            if (s == "IN") {
                Stu tmp;
                cin >> tmp.id >> tmp.ch >> tmp.ma;
                tmp.sum = tmp.ch + tmp.ma;
                pq.push(tmp);
            } else if (s == "MAX") {
                if (!pq.empty()) {
                    cout << pq.top().id << " " << pq.top().sum << endl;
                }
            } else if (s == "OUT") {
                if (!pq.empty()) {
                    pq.pop();
                }
            } else if (s == "COUNT") {
                cout << pq.size() << endl;
            }
        } return 0;
    }
    
    
    • @ 2023-7-23 16:56:42

      你这个题解有趣

    • @ 2023-8-7 23:04:09

      你真逗呵呵

    • @ 2023-8-10 19:36:35

      你那个箭头(下拉菜单)怎么做的??

    • @ 2023-8-11 18:01:17

      你抄了下面一个人的!!!(恼)!

    • @ 2023-8-11 18:04:04

      你肯定试了他的第一个代码,然后又发了他的第二个代码作题解。(你可别被我逮住了!)

    • @ 2023-8-11 18:04:56

      我告诉你,我眼睛不瞎!

    • @ 2023-8-12 14:55:55

      /user/8820
      你说谁呢??

    • @ 2023-8-12 20:27:15
  • 7
    @ 2023-8-10 20:14:37

    我以为应该有点难度 不废话,上思路!!!

    点我查看思路

    恭喜你!!迈出了第一步!!!告诉你,这是一道水题这道题用优先队列,然后……

    点我查看代码
    #include <bits/stdc++.h>//郭泽宇 (Gzy)
    using namespace std;
    
    struct Stu {
        int id;
        int ch, ma, sum;
    };
    
    struct cmp {
        bool operator () (Stu x, Stu y) {
            return x.ch + x.ma < y.ch + y.ma;
        }
    };
    
    priority_queue<Stu, vector<Stu>, cmp> pq;
    
    int main() {
        int n;
        cin >> n;
        for (int tool = 0; tool < n; tool++) {
            string s;
            cin >> s;
            if (s == "IN") {
                Stu tmp;
                cin >> tmp.id >> tmp.ch >> tmp.ma;
                tmp.sum = tmp.ch + tmp.ma;
                pq.push(tmp);
            } else if (s == "MAX") {
                if (!pq.empty()) {
                    cout << pq.top().id << " " << pq.top().sum << endl;
                }
            } else if (s == "OUT") {
                if (!pq.empty()) {
                    pq.pop();
                }
            } else if (s == "COUNT") {
                cout << pq.size() << endl;
            }
        } return 0;;
    }
    
    警告!!警告!!陷阱!!陷阱!! 恭喜你点开了陷阱!! 不好意思,刚刚的代码…… 编译错误!!
    AC代码
    #include <bits/stdc++.h>//郭泽宇 (Gzy)
    
    using namespace std;
    
    struct Stu {
        int id
        int ch, ma, sum;
    };
    
    struct cmp {
        bool operator () (Stu x, Stu y) {
            return x.ch + x.ma < y.ch + y.ma;
        }
    };
    
    priority_queue<Stu, vector<Stu>, cmp> pq;
    
    int main() {
        int n;
        cin >> n;
        for (int tool = 0; tool < n; tool++) {
            string s;
            cin >> s;
            if (s == "IN") {
                Stu tmp;
                cin >> tmp.id >> tmp.ch >> tmp.ma;
                tmp.sum = tmp.ch + tmp.ma;
                pq.push(tmp);
            } else if (s == "MAX") {
                if (!pq.empty()) {
                    cout << pq.top().id << " " << pq.top().sum << endl;
                }
            } else if (s == "OUT") {
                if (!pq.empty()) {
                    pq.pop();
                }
            } else if (s == "COUNT") {
                cout << pq.size() << endl;
            }
        } return 0;
    }
    
    警告!!警告!!陷阱×2!!!

    刚刚的代码还是…… 编译错误!!

    真AC代码
    #include <bits/stdc++.h>//郭泽宇 (Gzy)
    
    using namespace std;
    
    struct Stu {
        int id;
        int ch, ma, sum;
    };
    
    struct cmp {
        bool operator () (Stu x, Stu y) {
            return x.ch + x.ma < y.ch + y.ma;
        }
    };
    
    priority_queue<Stu, vector<Stu>, cmp> pq;
    
    int main() {
        int n;
        cin >> n;
        for (int tool = 0; tool < n; tool++) {
            string s;
            cin >> s;
            if (s == "IN") {
                Stu tmp;
                cin >> tmp.id >> tmp.ch >> tmp.ma;
                tmp.sum = tmp.ch + tmp.ma;
                pq.push(tmp);
            } else if (s == "MAX") {
                if (!pq.empty()) {
                    cout << pq.top().id << " " << pq.top().sum << endl;
                }
            } else if (s == "OUT") {
                if (!pq.empty()) {
                    pq.pop();
                }
            } else if (s == "COUNT") {
                cout << pq.size() << endl;
            }
        } return 0;
    }
    

    题解不易,点赞 → 抱走 哦~

    • -8
      @ 2023-7-23 14:38:43
      点我展开解题思路

      解题思路

      • 这道题其实挺简单的!!
      • 你现在回答了多少分呢?不可以抄袭题解的啦
      • 当然 既然你已经打开了 那么就可以来看看解题思路
      • 这道题使用优先队列处理即可,需要让总成绩高的人优先级更高。

      所以 你会了吗


      #include <bits/stdc++.h>
      
      using namespace std;
      
      struct Stu {
          int id;
          int ch, ma, sum;
      };
      
      struct cmp {
          bool operator () (Stu x, Stu y) {
              return x.ch + x.ma < y.ch + y.ma;
          }
      };
      
      priority_queue<Stu, vector<Stu>, cmp> pq;
      
      int main() {
          int n;
          cin >> n;
          for (int tool = 0; tool < n; tool++) {
              string s;
              cin >> s;
              if (s == "IN") {
                  Stu tmp;
                  cin >> tmp.id >> tmp.ch >> tmp.ma;
                  tmp.sum = tmp.ch + tmp.ma;
                  pq.push(tmp);
              } else if (s == "MAX") {
                  if (!pq.empty()) {
                      cout << pq.top().id << " " << pq.top().sum << endl;
                  }
              } else if (s == "OUT") {
                  if (!pq.empty()) {
                      pq.pop();
                  }
              } else if (s == "COUNT") {
                  cout << pq.size() << endl;
              }
          } return 0;
      }
      

      你们感谢郭泽宇去吧哈哈哈

      解题不易 请给个赞~

      加油 自己做吧哈哈哈

      • -14
        @ 2023-7-6 16:12:37

        使用优先队列处理即可,需要让总成绩高的人优先级更高。

        核心代码
        
        struct Student {
            int id, a, b;
        };
        struct cmp {
            bool operator()(Student x, Student y)
            {
                return x.a + x.b < y.a + y.b;
            }
        };
        
        • 1

        信息

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