problemscpp
A collection of my answers to algorithm problems in c++.
载入中...
搜索中...
未找到
codeforces::beautiful_average 命名空间参考

函数

int main (istream &cin, ostream &cout)
 
 TEST (beautiful_average, case1)
 

函数说明

◆ main()

int codeforces::beautiful_average::main ( istream & cin,
ostream & cout )

在文件 codeforces.cpp13 行定义.

13 {
14 int t;
15 cin >> t;
16 while(t--) {
17 int n;
18 cin >> n;
19 vector<int> arr(n);
20 vector<int> pref_sum(n + 1, 0);
21 for(int i = 0; i < n; i++) {
22 cin >> arr[i];
23 pref_sum[i + 1] = pref_sum[i] + arr[i];
24 }
25 int ans = -1;
26 for(int i = 0; i < n; i++) {
27 for(int j = i; j < n; j++) {
28 int sum = pref_sum[j + 1] - pref_sum[i];
29 int avg = sum / (j - i + 1);
30 ans = max(avg, ans);
31 }
32 }
33 cout << ans << endl;
34 }
35 return 0;
36 }
vector< vector< int > > ans

被这些函数引用 TEST().

◆ TEST()

codeforces::beautiful_average::TEST ( beautiful_average ,
case1  )

在文件 codeforces_test.cpp9 行定义.

9 {
10 istringstream in("3\n4\n3 3 3 3\n5\n7 1 6 9 9\n5\n3 4 4 4 3\n");
11 auto out = ostringstream();
12 main(in, out);
13 const auto ans = out.str();
14 ASSERT_EQ("3\n9\n4\n", ans);
15 }
int main(istream &cin, ostream &cout)

引用了 main().