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

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-;
  15. const double pi = acos(-1.0);
  16. const double inf = ~0u>>;
  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 = ; i<= n; i++)
  23. cin>>a[i];
  24. int s = -INF;
  25. for(i = ;i <= n ;i++)
  26. for(j = i ; j <= n ;j++)
  27. {
  28. int ts = ;
  29. int o = ;
  30. for(g = i ; g <= j; g++)
  31. {
  32. b[o++] = a[g];
  33. }
  34. int e = ;
  35. for(g = ; g < i; g++)
  36. c[e++] = a[g];
  37. for(g = j+ ; g <= n ;g++)
  38. c[e++] = a[g];
  39. sort(b,b+o);
  40. sort(c,c+e);
  41. int ko = e-,kk=;
  42. for(g = ;g <= o ; g++)
  43. {
  44. if(ko==-||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 = ;g < o ; g++)
  54. ts+=b[g];
  55. s = max(ts,s);
  56. }
  57. cout<<s<<endl;
  58. return ;
  59. }

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-;
  15. const double pi = acos(-1.0);
  16. const double inf = ~0u>>;
  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 = ; i < n ; i++)
  25. for(j = ;j < m ;j++)
  26. cin>>a[i][j];
  27. }
  28. else
  29. {
  30. for(i = ; i < n ;i++)
  31. for(j = ; 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 = ; i < (<<m) ;i++)
  39. {
  40. int ans = ;
  41. for(j = ; j < n; j++)
  42. {
  43. int o = ;
  44. for(g = ; g < m ; g++)
  45. {
  46. if((a[j][g]<<g)!=(i&(<<g)))
  47. o++;
  48. }
  49. ans+=min(o,m-o);
  50. }
  51. cnt = min(cnt,ans);
  52. }
  53. }
  54. else
  55. {
  56. for(i = ;i < m ; i++)
  57. {
  58. int ans = ;
  59. for(j = ;j < m ;j++)
  60. {
  61. if(j==i) continue;
  62. int o = ;
  63. for(g = ; 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\n";
  76.  
  77. return ;
  78. }

Codeforces Round #243 (Div. 1)的更多相关文章

  1. Codeforces Round #243 (Div. 2) B(思维模拟题)

    http://codeforces.com/contest/426/problem/B B. Sereja and Mirroring time limit per test 1 second mem ...

  2. Codeforces Round #243 (Div. 1) A题

    http://codeforces.com/contest/425/problem/A 题目链接: 然后拿出这道题目是很多人不会分析题目,被题目吓坏了,其中包括我自己,想出复杂度,一下就出了啊!真是弱 ...

  3. Codeforces Round #243 (Div. 2) Problem B - Sereja and Mirroring 解读

    http://codeforces.com/contest/426/problem/B 对称标题的意思大概是.应当指出的,当线数为奇数时,答案是线路本身的数 #include<iostream& ...

  4. Codeforces Round #243 (Div. 2) C. Sereja and Swaps

    由于n比较小,直接暴力解决 #include <iostream> #include <vector> #include <algorithm> #include ...

  5. Codeforces Round #243 (Div. 2) B. Sereja and Mirroring

    #include <iostream> #include <vector> #include <algorithm> using namespace std; in ...

  6. Codeforces Round #243 (Div. 2) A. Sereja and Mugs

    #include <iostream> #include <vector> #include <algorithm> #include <numeric> ...

  7. Codeforces Round #243 (Div. 2) C. Sereja and Swaps(优先队列 暴力)

    题目 题意:求任意连续序列的最大值,这个连续序列可以和其他的 值交换k次,求最大值 思路:暴力枚举所有的连续序列.没做对是因为 首先没有认真读题,没看清交换,然后,以为是dp或者贪心 用了一下贪心,各 ...

  8. Codeforces Round #243 (Div. 2) A~C

    题目链接 A. Sereja and Mugs time limit per test:1 secondmemory limit per test:256 megabytesinput:standar ...

  9. Codeforces Round #243 (Div. 1)-A,B,C-D

    此CF真是可笑.. . 由于早晨7初始点,因此,要做好CF时间已经17没有休息一小时,加上中午5小时耐力赛. 心里很清楚.是第一个问题的时候,几乎被解读为寻求最大的领域和.然后找到一个水体,快速A降. ...

  10. Codeforces Round #243 (Div. 2)——Sereja and Swaps

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u012476429/article/details/24665103 题目链接 题意: 给定一个整数 ...

随机推荐

  1. mysql----其他小技巧

    小技巧: min/max优化 在表中,一般都是经过优化的. 如下地区表 id area pid 1 中国 0 2 北京 1 ... 3115 3113 我们查min(id), id是主键,查Min(i ...

  2. C.Candy

    There are NN children standing in a line. Each child is assigned a rating value. You are giving cand ...

  3. CentOS 7.2安装Jenkins自动构建Git项目

    1.环境 本文使用VMWare虚拟机进行实验. 最终实现目标,在Jenkins服务器上新建构建任务,从Git服务器上拉取master HEAD(不编译,仅演示),部署到"目标服务器" ...

  4. Linux时间子系统之(一):时间的基本概念【转】

    本文转载自:http://www.wowotech.net/timer_subsystem/time_concept.html 本文使用Q & A的方式来和大家以前探讨一下时间的基本概念 一. ...

  5. idea 设置背景图片

    按下 Ctrl+Shift+A 你会看到一个对话框 在里面输入 Set Background Image 进入设置背景图片窗口 设置背景图,点击确定即可 就一个好看,强大的编程工具了

  6. kafka 查询 SQL Query

    . SELECT COUNT(*) FROM wiseweb_crawler_foreignmedias WHERE site_id= AND (gathertime BETWEEN '2017-05 ...

  7. FPU同步(翻译)

    本篇翻译的原英文在:http://mauve.mizuumi.net/2013/06/16/desyncs-and-fpu-synchronization/#more-725(可能要FQ) 如果你曾经 ...

  8. Servlet初始配置 监听器和过滤器

    ServletContext:application范围内的参数 此所设定的参 来源: http://note.sdo.com/my 数,在JSP网页中可以使用下列方法来取得: ${initParam ...

  9. 【hdu 4374】One Hundred Layer

    [题目链接] 点击打开链接 [算法] 不难看出,这题可以用动态规划来解决 f[i][j]表示第i行第j列能够取得的最大分数 则如果向右走,状态转移方程为f[i][j]=max{f[i-1][k]+a[ ...

  10. javascript之数组的6种去重方法

    去重 var arr=[11,11,333,4,4,5,66,66,7]; // 方法一:在新数组内判断不存在时加入 var newarr1=[]; function quchong1(){ for( ...