[Codeforces 425A] Sereja and Swaps
[题目链接]
https://codeforces.com/contest/425/problem/A
[算法]
枚举最终序列的左端点和右端点 , 尝试用这段区间中小的数与区间外大的数交换
时间复杂度 : O(N^3logN)
[代码]
#include<bits/stdc++.h>
using namespace std;
const int MAXN = ;
const int inf = 2e9; int n , k;
int a[MAXN],b[MAXN],value[MAXN]; template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
template <typename T> inline void read(T &x)
{
T f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
} int main()
{ read(n); read(k);
for (int i = ; i <= n; i++) read(value[i]);
int ans = -inf;
for (int i = ; i <= n; i++)
{
for (int j = i; j <= n; j++)
{
int la = , lb = , cnt = ;
for (int x = ; x <= n; x++)
{
if (x >= i && x <= j)
{
a[++la] = value[x];
cnt += value[x];
} else
b[++lb] = value[x];
}
sort(a + ,a + la + );
sort(b + ,b + lb + ,greater<int>());
for (int x = ; x <= min(la,min(lb,k)); x++)
{
if (b[x] - a[x] > )
cnt += b[x] - a[x];
else break;
}
ans = max(ans,cnt);
}
}
printf("%d\n",ans); return ; }
[Codeforces 425A] Sereja and Swaps的更多相关文章
- Codeforces 425A Sereja and Swaps(暴力枚举)
题目链接:A. Sereja and Swaps 题意:给定一个序列,能够交换k次,问交换完后的子序列最大值的最大值是多少 思路:暴力枚举每一个区间,然后每一个区间[l,r]之内的值先存在优先队列内, ...
- codeforces 425A Sereja and Swaps(模拟,vector,枚举区间)
题目 这要学习的是如何枚举区间,vector的基本使用(存入,取出,排序等),这题的思路来自: http://www.tuicool.com/articles/fAveE3 //vector 可以用s ...
- codeforces C. Sereja and Swaps
http://codeforces.com/contest/426/problem/C 题意:找出连续序列的和的最大值,可以允许交换k次任意位置的两个数. 思路:枚举区间,依次把区间内的比较小的数换成 ...
- [ An Ac a Day ^_^ ] CodeForces 426C Sereja and Swaps 优先队列
题意: 给你一个有n个数的序列 取一个区间 这个区间内的数可以与区间外的值交换k次 问这样的区间最大值是多少 思路: 看数据是200 时间复杂度O(n*n) 应该可以暴力 顺便学习一下优先队列 枚举区 ...
- Codeforces Round #243 (Div. 1)A. Sereja and Swaps 暴力
A. Sereja and Swaps time limit per test 1 second memory limit per test 256 megabytes input standard ...
- [codeforces 339]E. Three Swaps
[codeforces 339]E. Three Swaps 试题描述 Xenia the horse breeder has n (n > 1) horses that stand in a ...
- Codeforces Round #243 (Div. 2) C. Sereja and Swaps
由于n比较小,直接暴力解决 #include <iostream> #include <vector> #include <algorithm> #include ...
- Codeforces Round #243 (Div. 2) C. Sereja and Swaps(优先队列 暴力)
题目 题意:求任意连续序列的最大值,这个连续序列可以和其他的 值交换k次,求最大值 思路:暴力枚举所有的连续序列.没做对是因为 首先没有认真读题,没看清交换,然后,以为是dp或者贪心 用了一下贪心,各 ...
- Codeforces Round #243 (Div. 2)——Sereja and Swaps
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u012476429/article/details/24665103 题目链接 题意: 给定一个整数 ...
随机推荐
- nginx+redis安装配置(内存型数据库)实现session的共享
注意:借鉴原文章:http://www.cnblogs.com/roy-blog/p/7196054.html 感兴趣的可以加一下481845043 java交流群,共同进步. 1 session的概 ...
- Python接口测试中通过登录接口获取实时token
1.封装login_token 2.headers:对应登录请求头部信息 3.request_param:登录的参数数据 4.json.dumps:将一个Python数据结构转换为JSON 5.dic ...
- insert,extend
#insert s = ['8','9','sfd',('45','00'),{'01':'56'}] s0 = [] while 1 : extend = input("请输入要添加的内容 ...
- jQuery调用WCF 说明
在项目中用过一些WCF的技术这篇文章是对以前用过的一点东西的一个梳理 一,webconfig的配置除了一般的配置外,与WCF相关的配置如下 <system.serviceModel> ...
- IntelliJ IDEA 13.1.1版本偶然的错误
总之很悲催也很浪费时间,这款软件很喜欢,不想卸载 图片中的style.css使得style.css一直是文本形式 将style.css删除就恢复正常了,这个错误弄了半天才搞定,心累.
- Windows学习总结(12)——Windows 10系统开始运行-cmd命令大全
gpedit.msc-----组策略 sndrec32-------录音机 Nslookup-------IP地址侦测器 explorer-------打开资源管理器 logoff---------注 ...
- 【HDOJ6118】度度熊的交易计划(费用流)
题意: 度度熊参与了喵哈哈村的商业大会,但是这次商业大会遇到了一个难题: 喵哈哈村以及周围的村庄可以看做是一共由n个片区,m条公路组成的地区. 由于生产能力的区别,第i个片区能够花费a[i]元生产1个 ...
- Writing Code-Codeforces511C**
http://codeforces.com/problemset/problem/544/C 完全背包 dp[i][j]表示第i行有j个bug #include<stdio.h> #inc ...
- operamasks—omBorderLayout布局
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- 解决confluence的乱码问题
使用confluence时发现一些含有中文的页面中,中文都变成了问号. 继续搜索解决方案,发现时数据库中数据的格式不对, 在mysql中输入以下命令: mysql> show variabl ...