A. Flipping Game

链接:http://codeforces.com/contest/327/problem/A

题意:从 i 到 j 翻转一次使得 1 的 个数最多~

直接暴力搞~

 1 #include <cstdio>
 2 #include <cmath>
 3 #include <iostream>
 4 using namespace std;
 5 int N;
 6 int a[105], b[105];
 7 int main( )
 8 {
 9     while(scanf("%d", &N)!= EOF){
10         for(int i=0; i<N; ++ i){
11             scanf("%d", &a[i]);
12             b[i]=a[i];
13         }
14         int ans=-1;
15         for( int i=0; i<N; ++ i ){
16             for( int j=i; j<N; ++ j ){
17                 for( int k=i; k<=j ; ++ k){
18                     b[k]=1-a[k];
19                 }
20                 int t=0;
21                 for( int k=0; k<N; ++ k ){
22                     if(b[k]) t++;
23                     ans=ans>t?ans:t;
24                     b[k]=a[k];
25                 }    
26             }
27         }
28         printf("%d\n", ans);
29     }
30     return 0;
31 }
View Code

相关文章:

  • 2022-12-23
  • 2021-07-20
  • 2021-07-19
  • 2021-09-20
  • 2021-12-04
  • 2021-07-11
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-19
  • 2021-06-24
  • 2022-02-09
  • 2022-12-23
  • 2021-05-25
  • 2021-06-25
  • 2022-12-23
相关资源
相似解决方案