codeforces 192a

link: http://codeforces.com/contest/330/problem/A

brute force. 

 1 /*
 2 ID: zypz4571
 3 LANG: C++
 4 TASK: 191a.cpp
 5  */
 6 
 7 #include <cstdio>
 8 #include <cstdlib>
 9 #include <cstring>
10 #include <cmath>
11 #include <cctype>
12 #include <algorithm>
13 #include <queue>
14 #include <set>
15 #include <queue>
16 #include <list>
17 #include <map>
18 #define INF 0x3f3f3f3f
19 #define mid int m=(l+r)/2
20 using namespace std;
21 int a[102];
22 int main ( int argc, char *argv[] )
23 {
24 #ifndef ONLINE_JUDGE
25     freopen("191a.in", "r", stdin);
26 #endif
27     int n, n1=0, cnt=0, Max=0; scanf("%d", &n);
28     for (int i=0; i<n; ++i){
29         scanf("%d",a+i); if(a[i]) n1++;
30     }
31     if (n1 == n) Max = n1-1;
32     else 
33     {
34         Max = n1;
35         for (int i=0; i<n; ++i) {
36             for (int j=0; j<n; ++j) {
37                 cnt = n1;
38                 for (int k=i; k<=j; ++k) {
39                     if (!a[k]) cnt++; else cnt--;
40                 }
41                 if (cnt > Max) Max = cnt;
42             }
43         }
44     }
45     printf("%d
", Max);
46 
47         return EXIT_SUCCESS;
48 }                /* ----------  end of function main  ---------- */

It is so easy. However, I got a WA at first. sad......

原文地址:https://www.cnblogs.com/liuxueyang/p/3204601.html