-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdaisy.java
89 lines (74 loc) · 2.51 KB
/
daisy.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import java.io.*;
import java.util.StringTokenizer;
public class daisy {
static class Solver {
void solve(InputReader in, PrintWriter out) throws Exception {
// Here goes your code
int n = in.nextInt();
int[] petals = new int[n];
for (int i = 0; i < n; i++) {
petals[i] = in.nextInt();
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
int flowers = j - i + 1;
int sum = 0;
for (int k = i; k <= j; k++) {
sum += petals[k];
}
if (sum % flowers != 0) continue;
int avg = sum / flowers;
for (int k = i; k <= j; k++) {
if (petals[k] == avg) {
ans++;
break; // we want the number of photos that have avg flowers not the nbr of avg flowers total
}
}
}
}
out.print(ans);
}
}
public static void main(String... args) throws Exception {
InputReader in = new InputReader();
PrintWriter out = new PrintWriter(System.out);
new Solver().solve(in, out);
out.close();
in.close();
}
static class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
InputReader(InputStream is) throws Exception {
reader = new BufferedReader(new InputStreamReader(is));
}
InputReader(String inFilePath) throws Exception {
this(new FileInputStream(inFilePath));
}
InputReader() throws Exception {
this(System.in);
}
String next() throws Exception {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
String nextLine() throws Exception {
return reader.readLine();
}
int nextInt() throws Exception {
return Integer.parseInt(next());
}
long nextLong() throws Exception {
return Long.parseLong(next());
}
double nextDouble() throws Exception {
return Double.parseDouble(next());
}
void close() throws Exception {
reader.close();
}
}
}