zoukankan      html  css  js  c++  java
  • Codeforces Round #243 (Div. 1)

    ---恢复内容开始---

    A

    枚举l,r

     1 #include <iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 #include<stdlib.h>
     6 #include<vector>
     7 #include<cmath>
     8 #include<queue>
     9 #include<set>
    10 using namespace std;
    11 #define N 210
    12 #define LL long long
    13 #define INF 0xfffffff
    14 const double eps = 1e-8;
    15 const double pi = acos(-1.0);
    16 const double inf = ~0u>>2;
    17 int a[N],b[N],c[N];
    18 int main()
    19 {
    20     int i,j,n,k,g;
    21     cin>>n>>k;
    22     for(i = 1; i<= n; i++)
    23     cin>>a[i];
    24     int s = -INF;
    25     for(i = 1 ;i <= n ;i++)
    26         for(j = i ; j <= n ;j++)
    27         {
    28             int ts = 0;
    29             int o = 0 ;
    30             for(g = i ; g <= j; g++)
    31             {
    32                 b[o++] = a[g];
    33             }
    34             int e = 0;
    35             for(g = 1; g < i; g++)
    36             c[e++] = a[g];
    37             for(g = j+1 ; g <= n ;g++)
    38             c[e++] = a[g];
    39             sort(b,b+o);
    40             sort(c,c+e);
    41             int ko = e-1,kk=0;
    42             for(g = 0 ;g <= o ; g++)
    43             {
    44                 if(ko==-1||kk==k) break;
    45                 if(c[ko]>b[g])
    46                 {
    47                     swap(c[ko],b[g]);
    48                     ko--;
    49                     kk++;
    50                 }
    51                 else break;
    52             }
    53             for(g = 0 ;g < o ; g++)
    54             ts+=b[g];
    55             s = max(ts,s);
    56         }
    57     cout<<s<<endl;
    58     return 0;
    59 }
    View Code

    B

    使每个连通块 变成矩形 所需改变的最小次数。

    如果某一行的状态或某一列的状态确定了,整体的划分是确定的。如果列数小于等于K状压枚举列的状态,否则肯定有一列的状态是不变的 枚举那一列的状态。

     1 #include <iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 #include<stdlib.h>
     6 #include<vector>
     7 #include<cmath>
     8 #include<queue>
     9 #include<set>
    10 using namespace std;
    11 #define N 105
    12 #define LL long long
    13 #define INF 0xfffffff
    14 const double eps = 1e-8;
    15 const double pi = acos(-1.0);
    16 const double inf = ~0u>>2;
    17 int a[N][N];
    18 int main()
    19 {
    20     int i,j,n,m,k,g;
    21     cin>>n>>m>>k;
    22     if(m<n)
    23     {
    24         for(i = 0 ; i < n ; i++)
    25             for(j = 0 ;j < m ;j++)
    26             cin>>a[i][j];
    27     }
    28     else
    29     {
    30         for(i = 0; i < n ;i++)
    31             for(j = 0; j < m ;j++)
    32             cin>>a[j][i];
    33         swap(n,m);
    34     }
    35     int cnt = INF;
    36     if(m<=k)
    37     {
    38         for(i = 0; i < (1<<m) ;i++)
    39         {
    40             int ans = 0;
    41             for(j = 0 ; j < n; j++)
    42             {
    43                 int o = 0;
    44                 for(g = 0 ; g < m ; g++)
    45                 {
    46                     if((a[j][g]<<g)!=(i&(1<<g)))
    47                     o++;
    48                 }
    49                 ans+=min(o,m-o);
    50             }
    51             cnt = min(cnt,ans);
    52         }
    53     }
    54     else
    55     {
    56         for(i = 0;i < m ; i++)
    57         {
    58             int ans = 0;
    59             for(j = 0;j < m ;j++)
    60             {
    61                 if(j==i) continue;
    62                 int o = 0;
    63                 for(g = 0; g < n ; g++)
    64                 {
    65                     if(a[g][j]!=a[g][i]) o++;
    66                 }
    67                 ans+=min(o,n-o);
    68             }
    69             cnt = min(cnt,ans);
    70         }
    71     }
    72     if(cnt<=k)
    73     cout<<cnt<<endl;
    74     else
    75     cout<<"-1
    ";
    76 
    77     return 0;
    78 }
    View Code
  • 相关阅读:
    寒假每日总结(八)
    寒假每日总结(七)
    寒假每日总结(六)
    2020-2.19
    2020-2.18
    寒假每日总结-2020.2.11
    寒假每日总结-2020.2.10
    寒假每日总结-2020.2.9
    寒假每日总结
    寒假每日总结——2020.2.6
  • 原文地址:https://www.cnblogs.com/shangyu/p/3700199.html
Copyright © 2011-2022 走看看