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 题目链接 题意: 给定一个整数 ...
随机推荐
- mysql----其他小技巧
小技巧: min/max优化 在表中,一般都是经过优化的. 如下地区表 id area pid 1 中国 0 2 北京 1 ... 3115 3113 我们查min(id), id是主键,查Min(i ...
- C.Candy
There are NN children standing in a line. Each child is assigned a rating value. You are giving cand ...
- CentOS 7.2安装Jenkins自动构建Git项目
1.环境 本文使用VMWare虚拟机进行实验. 最终实现目标,在Jenkins服务器上新建构建任务,从Git服务器上拉取master HEAD(不编译,仅演示),部署到"目标服务器" ...
- Linux时间子系统之(一):时间的基本概念【转】
本文转载自:http://www.wowotech.net/timer_subsystem/time_concept.html 本文使用Q & A的方式来和大家以前探讨一下时间的基本概念 一. ...
- idea 设置背景图片
按下 Ctrl+Shift+A 你会看到一个对话框 在里面输入 Set Background Image 进入设置背景图片窗口 设置背景图,点击确定即可 就一个好看,强大的编程工具了
- kafka 查询 SQL Query
. SELECT COUNT(*) FROM wiseweb_crawler_foreignmedias WHERE site_id= AND (gathertime BETWEEN '2017-05 ...
- FPU同步(翻译)
本篇翻译的原英文在:http://mauve.mizuumi.net/2013/06/16/desyncs-and-fpu-synchronization/#more-725(可能要FQ) 如果你曾经 ...
- Servlet初始配置 监听器和过滤器
ServletContext:application范围内的参数 此所设定的参 来源: http://note.sdo.com/my 数,在JSP网页中可以使用下列方法来取得: ${initParam ...
- 【hdu 4374】One Hundred Layer
[题目链接] 点击打开链接 [算法] 不难看出,这题可以用动态规划来解决 f[i][j]表示第i行第j列能够取得的最大分数 则如果向右走,状态转移方程为f[i][j]=max{f[i-1][k]+a[ ...
- javascript之数组的6种去重方法
去重 var arr=[11,11,333,4,4,5,66,66,7]; // 方法一:在新数组内判断不存在时加入 var newarr1=[]; function quchong1(){ for( ...