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

AcWing 2014. 岛 更多...

#include <acwing.h>

静态 Public 成员函数

static int main (istream &, ostream &)
 

详细描述

AcWing 2014. 岛

在文件 acwing.h183 行定义.

成员函数说明

◆ main()

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

在文件 acwing.cpp483 行定义.

483 {
484 int n;
485 cin >> n;
486 auto *above = new bool[n];
487 auto heights = set<unsigned int>();
488 auto m = map<unsigned int, vector<unsigned int>>();
489 for(int i = 0; i < n; i++) {
490 int height;
491 cin >> height;
492 heights.insert(height);
493 above[i] = true;//露出水面
494 if(!m.contains(height)) {
495 m[height] = vector<unsigned int>();
496 }
497 m[height].push_back(i);
498 }
499 int count = 1;
500 int max = count;
501 for(auto height: heights) {
502 for(const auto index: m[height]) {
503 above[index] = false;
504 if(0 < index && index + 1 < n) {
505 if(above[index - 1] && above[index + 1]) {
506 count++;
507 } else if(!above[index - 1] && !above[index + 1]) {
508 count--;
509 }
510 } else if(index == 0 && !above[1] || index == n - 1 && !above[n - 2]) {
511 count--;
512 }
513 }
514 if(max < count) {
515 max = count;
516 }
517 }
518 cout << max;
519 delete[] above;
520 return 0;
521 }

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


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