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

AcWing 3347. 菊花链 更多...

#include <acwing.h>

静态 Public 成员函数

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

详细描述

AcWing 3347. 菊花链

在文件 acwing.h1291 行定义.

成员函数说明

◆ main()

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

在文件 acwing.cpp4166 行定义.

4166 {
4167 int n;
4168 cin >> n;
4169 auto *flowers = new int[n];
4170 auto *prefix_sum = new int[n];
4171 auto location = unordered_map<int, unordered_set<int>>();
4172 int sum = 0;
4173 for(int i = 0; i < n; i++) {
4174 cin >> flowers[i];
4175 sum += flowers[i];
4176 prefix_sum[i] = sum;
4177 location[flowers[i]].insert(i);
4178 }
4179 int ans = 0;
4180 for(int i = 0; i < n; i++) {
4181 for(int j = i; j < n; j++) {
4182 const int len = j - i + 1;
4183 sum = prefix_sum[j] - (i - 1 >= 0 ? prefix_sum[i - 1] : 0);
4184 if(sum % len == 0) {
4185 int avg = sum / len;
4186 for(const auto flower: location[avg]) {
4187 if(i <= flower && flower <= j) {
4188 ans++;
4189 break;
4190 }
4191 }
4192 }
4193 }
4194 }
4195 cout << ans;
4196 delete[] flowers;
4197 delete[] prefix_sum;
4198 return 0;
4199 }

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


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