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

AcWing 1987. 粉刷栅栏 更多...

#include <acwing.h>

静态 Public 成员函数

static int main (istream &, ostream &)
 

详细描述

AcWing 1987. 粉刷栅栏

在文件 acwing.h353 行定义.

成员函数说明

◆ main()

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

在文件 acwing.cpp878 行定义.

878 {
879 int n;
880 cin >> n;
881 auto m = map<int, int>();
882 int current = 0;
883 for(int i = 0; i < n; i++) {
884 int length;
885 char direction;
886 cin >> length >> direction;
887 if(direction == 'R') {
888 if(!m.contains(current)) {
889 m.insert(pair(current, 1));
890 } else {
891 m[current]++;
892 }
893 if(!m.contains(current + length)) {
894 m.insert(pair(current + length, -1));
895 } else {
896 m[current + length]--;
897 }
898 current += length;
899 } else {
900 if(!m.contains(current)) {
901 m.insert(pair(current, -1));
902 } else {
903 m[current]--;
904 }
905 if(!m.contains(current - length)) {
906 m.insert(pair(current - length, 1));
907 } else {
908 m[current - length]++;
909 }
910 current -= length;
911 }
912 }
913 unsigned int layer_count = 0;
914 unsigned int count = 0;
915 bool above2 = false;
916 int prev;
917 for(const auto p: m) {
918 layer_count += p.second;
919 if(layer_count >= 2) {
920 if(above2) {
921 count += p.first - prev;
922 }
923 above2 = true;
924 prev = p.first;
925 } else {
926 if(above2) {
927 count += p.first - prev;
928 }
929 above2 = false;
930 }
931 }
932 cout << count;
933 return 0;
934 }

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


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