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

AcWing 1945. 奶牛棒球 更多...

#include <acwing.h>

静态 Public 成员函数

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

详细描述

AcWing 1945. 奶牛棒球

在文件 acwing.h474 行定义.

成员函数说明

◆ main()

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

在文件 acwing.cpp1312 行定义.

1312 {
1313 unsigned int count = 0;
1314 unsigned short n;
1315 cin >> n;
1316 auto cows = vector<unsigned int>();
1317 cows.resize(n);
1318 for(int i = 0; i < n; i++) {
1319 unsigned int cow;
1320 cin >> cow;
1321 cows[i] = cow;
1322 }
1323 sort(cows.begin(), cows.end());
1324 for(auto i = cows.begin(); i != cows.end(); ++i) {
1325 for(auto j = i + 1; j != cows.end(); ++j) {
1326 const unsigned int xy = *j - *i;
1327 auto min = lower_bound(j, cows.end(), *j + xy);
1328 auto max = upper_bound(j, cows.end(), *j + 2 * xy);
1329 count += max - min;
1330 }
1331 }
1332 cout << count;
1333 return 0;
1334 }

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


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