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

AcWing 1855. 愤怒的奶牛 更多...

#include <acwing.h>

静态 Public 成员函数

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

详细描述

AcWing 1855. 愤怒的奶牛

在文件 acwing.h788 行定义.

成员函数说明

◆ main()

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

在文件 acwing.cpp2305 行定义.

2305 {
2306 unsigned short n;
2307 cin >> n;
2308 auto hay = vector<unsigned int>();
2309 for(unsigned short i = 0; i < n; i++) {
2310 unsigned int x;
2311 cin >> x;
2312 hay.push_back(x);
2313 }
2314 sort(hay.begin(), hay.end());
2315 unsigned int maximum = 0;
2316 for(auto start = hay.begin(); start != hay.end(); ++start) {
2317 bool left_end = false;
2318 bool right_end = false;
2319 auto left = start;
2320 auto right = start;
2321 for(int i = 1;; i++) {
2322 if(!left_end) {
2323 auto l = lower_bound(hay.begin(), hay.end(), *left - i);
2324 if(l == hay.end() || l == left) {
2325 left_end = true;
2326 } else {
2327 left = l;
2328 }
2329 }
2330 if(!right_end) {
2331 auto r = upper_bound(hay.begin(), hay.end(), *right + i) - 1;
2332 if(r == hay.end() || r == right) {
2333 right_end = true;
2334 } else {
2335 right = r;
2336 }
2337 }
2338 if(left_end && right_end) {
2339 maximum = max(maximum, static_cast<unsigned int>(right - left) + 1);
2340 break;
2341 }
2342 }
2343 }
2344 cout << maximum;
2345 return 0;
2346 }

引用了 acwing::acwing1929::left , 以及 acwing::acwing1929::right.

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


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