Codeforces Round #243 (Div. 1)
---恢复内容开始---
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)的更多相关文章
- Codeforces Round #243 (Div. 2) B(思维模拟题)
http://codeforces.com/contest/426/problem/B B. Sereja and Mirroring time limit per test 1 second mem ...
- Codeforces Round #243 (Div. 1) A题
http://codeforces.com/contest/425/problem/A 题目链接: 然后拿出这道题目是很多人不会分析题目,被题目吓坏了,其中包括我自己,想出复杂度,一下就出了啊!真是弱 ...
- Codeforces Round #243 (Div. 2) Problem B - Sereja and Mirroring 解读
http://codeforces.com/contest/426/problem/B 对称标题的意思大概是.应当指出的,当线数为奇数时,答案是线路本身的数 #include<iostream& ...
- Codeforces Round #243 (Div. 2) C. Sereja and Swaps
由于n比较小,直接暴力解决 #include <iostream> #include <vector> #include <algorithm> #include ...
- Codeforces Round #243 (Div. 2) B. Sereja and Mirroring
#include <iostream> #include <vector> #include <algorithm> using namespace std; in ...
- Codeforces Round #243 (Div. 2) A. Sereja and Mugs
#include <iostream> #include <vector> #include <algorithm> #include <numeric> ...
- Codeforces Round #243 (Div. 2) C. Sereja and Swaps(优先队列 暴力)
题目 题意:求任意连续序列的最大值,这个连续序列可以和其他的 值交换k次,求最大值 思路:暴力枚举所有的连续序列.没做对是因为 首先没有认真读题,没看清交换,然后,以为是dp或者贪心 用了一下贪心,各 ...
- Codeforces Round #243 (Div. 2) A~C
题目链接 A. Sereja and Mugs time limit per test:1 secondmemory limit per test:256 megabytesinput:standar ...
- Codeforces Round #243 (Div. 1)-A,B,C-D
此CF真是可笑.. . 由于早晨7初始点,因此,要做好CF时间已经17没有休息一小时,加上中午5小时耐力赛. 心里很清楚.是第一个问题的时候,几乎被解读为寻求最大的领域和.然后找到一个水体,快速A降. ...
- Codeforces Round #243 (Div. 2)——Sereja and Swaps
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u012476429/article/details/24665103 题目链接 题意: 给定一个整数 ...
随机推荐
- Java中数组复制的几种方式以及数组合并
1.Object.clone() 简单直接,只能对源数组完整地复制 2.Arrays.copyOf(T[] original, int newLength) 可以只复制源数组中部分元素,但复制的起始位 ...
- C# XML序列化与反序列化与XML格式详解
1.https://www.cnblogs.com/sandyliu1999/p/4844664.html XML是有层次结构的,序列化实际就是内存化,用连续的结构化的内存来存储表示一个对象,那么这两 ...
- Spring Boot 整合 Listener
两种方法: 方法一: 使用注解 编写Listener,并使用@WebListener注解标记,在启动类使用注解:@ServletComponentScan package clc.user.liste ...
- android adb 源码框架分析(1 系统)【转】
本文转载自:http://blog.csdn.net/luansxx/article/details/25203269 ‘ Adb模块包括adb,adbd,源代码都在system/core/adb目录 ...
- proc_create的使用方法
proc_create的使用方法 proc文件系统是个有用的东东.创建一个proc虚拟文件,应用层通过读写该文件,即可实现与内核的交互.proc虚拟文件是如何创建的呢? 先看看比较简单的,创建proc ...
- 「网络流24题」「LuoguP2774」方格取数问题(最大流 最小割
Description 在一个有 m*n 个方格的棋盘中,每个方格中有一个正整数.现要从方格中取数,使任意 2 个数所在方格没有公共边,且取出的数的总和最大.试设计一个满足要求的取数算法.对于给定的方 ...
- uCareSystem:Ubuntu/Linux Mint的一体化系统更新和维护工具
对于任何一款允许用户还原电脑到之前状态(包括文件系统,安装的应用,以及系统设置)的操作系统来说,系统还原功能都是必备功能,它可以恢复系统故障以及其他的问题. 有的时候安装一个程序或者驱动可能让你的系统 ...
- Spring注解的(List&Map)特殊注入功能
一.先看一个示例演示:spring注解的一个特殊的注入功能. 首先,是定义一个接口,3个实现类. public interface GreetService { public String sayHe ...
- HTML 新属性
accesskey 属性 -- 代表链接的快捷键访问方式 定义了accesskey的链接可以使用快捷键(ALT+字母)访问. 主菜单与导航菜单使用accesskey,通常是不错的选择. 取值: 字母 ...
- ML一些零散记录
朴素贝叶斯的假定条件:变量独立同分布 一般情况下,越复杂的系统,过拟合的可能性就越高,一般模型相对简单的话泛化能力会更好一点,增加隐层数可以降低网络误差(也有文献认为不一定能有效降低),提高精度,但也 ...