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

A

枚举l,r

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 210
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
int a[N],b[N],c[N];
int main()
{
int i,j,n,k,g;
cin>>n>>k;
for(i = ; i<= n; i++)
cin>>a[i];
int s = -INF;
for(i = ;i <= n ;i++)
for(j = i ; j <= n ;j++)
{
int ts = ;
int o = ;
for(g = i ; g <= j; g++)
{
b[o++] = a[g];
}
int e = ;
for(g = ; g < i; g++)
c[e++] = a[g];
for(g = j+ ; g <= n ;g++)
c[e++] = a[g];
sort(b,b+o);
sort(c,c+e);
int ko = e-,kk=;
for(g = ;g <= o ; g++)
{
if(ko==-||kk==k) break;
if(c[ko]>b[g])
{
swap(c[ko],b[g]);
ko--;
kk++;
}
else break;
}
for(g = ;g < o ; g++)
ts+=b[g];
s = max(ts,s);
}
cout<<s<<endl;
return ;
}

B

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

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

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 105
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
int a[N][N];
int main()
{
int i,j,n,m,k,g;
cin>>n>>m>>k;
if(m<n)
{
for(i = ; i < n ; i++)
for(j = ;j < m ;j++)
cin>>a[i][j];
}
else
{
for(i = ; i < n ;i++)
for(j = ; j < m ;j++)
cin>>a[j][i];
swap(n,m);
}
int cnt = INF;
if(m<=k)
{
for(i = ; i < (<<m) ;i++)
{
int ans = ;
for(j = ; j < n; j++)
{
int o = ;
for(g = ; g < m ; g++)
{
if((a[j][g]<<g)!=(i&(<<g)))
o++;
}
ans+=min(o,m-o);
}
cnt = min(cnt,ans);
}
}
else
{
for(i = ;i < m ; i++)
{
int ans = ;
for(j = ;j < m ;j++)
{
if(j==i) continue;
int o = ;
for(g = ; g < n ; g++)
{
if(a[g][j]!=a[g][i]) o++;
}
ans+=min(o,n-o);
}
cnt = min(cnt,ans);
}
}
if(cnt<=k)
cout<<cnt<<endl;
else
cout<<"-1\n"; return ;
}

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. JSON和JavaScript对象

    var obj={width:100,height:200},这样的并不叫JSON,并且JSON只是一种数据格式,并不是具体的实例. 但很多人把这样的JS对象当成JSON,下面把这个问题讲清楚 一.J ...

  2. Eclipse设置java环境

    通用JRE环境设置: Window->Preferences->Java->Installed JREs 设置jre路径,如C:\Program Files\Java\jre1.8. ...

  3. MessageBox_ swt

    SWT有不同类型的对话框.有些对话框具有特殊的属性. MessageBox messageBox = new MessageBox(shell, SWT.OK|SWT.CANCEL); if (mes ...

  4. 蓝牙协议(bluetooth spec)

    1.概述:   蓝牙协议规范遵循开放系统互连参考模型(OSI/RM),从低到高地定义了蓝牙协议堆栈的各个层次. SIG(Session Initiation Protocol)所定义的蓝牙技术规范的目 ...

  5. download file by python in google colab

    https://stackoverflow.com/questions/15352668/download-and-decompress-gzipped-file-in-memory You need ...

  6. YTU 2451: 股市风云

    2451: 股市风云 时间限制: 1 Sec  内存限制: 128 MB 提交: 37  解决: 25 [提交][状态][讨论版] 题目描述 股市强烈动荡,有涨有跌.现在有一组数据表示各公司的涨跌(涨 ...

  7. js截取小数点后面2位

    1.substr var str = "Hello world!"; document.write(str.substr(3)); 输出:lo world! var str = & ...

  8. java前端学习步骤

    前端说的比较好的知乎:https://www.zhihu.com/question/22759296 网站开发绝杀技:https://ke.qq.com/course/20945?from=qqcha ...

  9. Codeforces-914F Substrings in a String (Bitset求T串中S串出现次数)

    之前有过区域赛,简化版问题: 给定一个小写字符组成的字符串S,(|S|<1e5,下标从1开始),现在有Q种操作,对于每个操作Q(Q<=1e5),输入opt, 如果opt==1,输入x,c, ...

  10. 使用Navicat连接MySQL出现1251错误

    问题:navicat连接mysql时报错:1251-Client does not support authentication protocol requested by server; consi ...