problemscpp
A collection of my answers to algorithm problems in c++.
载入中...
搜索中...
未找到
codeforces.cpp
浏览该文件的文档.
1//
2// Created by wangzhiheng on 17/10/2025.
3//
4#include "codeforces.h"
5#include <iosfwd>
6#include <iostream>
7#include <vector>
8
9using namespace std;
10
11namespace codeforces {
13 int main(istream &cin, ostream &cout) {
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 }
37 }// namespace beautiful_average
38
39 namespace beautiful_string {
40 int main(istream &cin, ostream &cout) {
41 int t;
42 cin >> t;
43 while(t--) {
44 int k;
45 string s;
46 cin >> k >> s;
47 int cnt = 0;
48 vector<int> ans = vector<int>();
49 for(int i = 0; i < k; i++) {
50 if(s[i] == '0') {
51 cnt++;
52 ans.push_back(i + 1);
53 }
54 }
55 cout << cnt << endl;
56 bool first = true;
57 for(int i = 0; i < ans.size(); i++) {
58 if(first) {
59 cout << ans[i];
60 first = false;
61 } else {
62 cout << " " << ans[i];
63 }
64 }
65 cout << endl;
66 }
67 return 0;
68 }
69 }// namespace beautiful_string
70}// namespace codeforces
int main(istream &cin, ostream &cout)
int main(istream &cin, ostream &cout)