problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
acwing::acwing1750类 参考

AcWing 1750. 救生员 更多...

#include <acwing.h>

静态 Public 成员函数

static int main (istream &cin, ostream &cout)
 

详细描述

AcWing 1750. 救生员

在文件 acwing.h978 行定义.

成员函数说明

◆ main()

int acwing::acwing1750::main ( istream &  cin,
ostream &  cout 
)
static

在文件 acwing.cpp3024 行定义.

3024 {
3025 int n;
3026 cin >> n;
3027 auto start = unordered_set<int>();
3028 auto end = unordered_set<int>();
3029 auto t = vector<pair<int, int>>();
3030 auto levels = vector<int>();
3031 levels.resize(1000);
3032 for(int i = 0; i < n; i++) {
3033 int t1;
3034 int t2;
3035 cin >> t1 >> t2;
3036 start.insert(t1);
3037 end.insert(t2);
3038 t.emplace_back(make_pair(t1, t2));
3039 }
3040 int level = 0;
3041 int maximum = 0;
3042 for(int i = 0; i < 1000; i++) {
3043 if(start.count(i) == 1) {
3044 level++;
3045 }
3046 if(end.count(i) == 1) {
3047 level--;
3048 }
3049 levels[i] = level;
3050 if(level > 0) {
3051 maximum++;
3052 }
3053 }
3054 int ans = 0;
3055 for(auto [t1, t2]: t) {
3056 int len = maximum;
3057 for(int i = t1; i < t2; i++) {
3058 if(levels[i] == 1) {
3059 len--;
3060 }
3061 }
3062 ans = max(ans, len);
3063 }
3064 cout << ans;
3065 return 0;
3066 }

被这些函数引用 acwing::TEST().


该类的文档由以下文件生成: