4 条题解
-
23
很简单的好吧(
(但是这个屑过了试了两遍才通过啊啊啊不管怎么样,先上思路!
点我解锁思路
好的,恭喜你迈开了成功的第一步!
不管怎么说,既然你点开了,我只能摊牌了:很简单,只需要使用
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; }
-
7
我以为应该有点难度 不废话,上思路!!!
点我查看思路
恭喜你!!迈出了第一步!!!告诉你,
这是一道水题这道题用优先队列,然后……点我查看代码
#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
点我展开解题思路
解题思路
- 这道题其实挺简单的!!
- 你现在回答了多少分呢?不可以抄袭题解的啦
- 当然 既然你已经打开了 那么就可以来看看解题思路
- 这道题使用优先队列处理即可,需要让总成绩高的人优先级更高。
所以 你会了吗
#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; }
你们感谢郭泽宇去吧哈哈哈
解题不易 请给个赞~
- 1
信息
- ID
- 246
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 4
- 标签
- (无)
- 递交数
- 1104
- 已通过
- 499
- 上传者