codeforces C. Sereja and Swaps
http://codeforces.com/contest/426/problem/C
题意:找出连续序列的和的最大值,可以允许交换k次任意位置的两个数。
思路:枚举区间,依次把区间内的比较小的数换成区间外的比较大的数。
#include <cstdio>
#include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std; int a[],b[],c[];
int n,kk;
bool cmp(int aa,int bb)
{
return aa>bb;
} int main()
{
cin>>n>>kk;
int ans=-;
for(int i=; i<=n; i++)
{
cin>>a[i];
ans=max(ans,a[i]);
}
for(int i=; i<=n; i++)
{
for(int j=i+; j<=n; j++)
{
int t=;
memset(b,,sizeof(b));
memset(c,,sizeof(c));
for(int k=i; k<=j; k++)
{
b[t++]=a[k];
}
int t1=;
for(int x=; x<i; x++)
{
c[t1++]=a[x];
}
for(int x=j+; x<=n; x++)
{
c[t1++]=a[x];
}
sort(b,b+t);
sort(c,c+t1,cmp);
int sum=;
for(int x=; x<=min(kk,t); x++)
{
if(b[x-]<c[x-]&&x<=t1)
{
sum+=c[x-];
}
else
sum+=b[x-];
}
for(int x=min(kk,t); x<t; x++)
{
sum+=b[x];
}
ans=max(ans,sum);
}
}
printf("%d\n",ans);
return ;
}
codeforces C. Sereja and Swaps的更多相关文章
- Codeforces 425A Sereja and Swaps(暴力枚举)
题目链接:A. Sereja and Swaps 题意:给定一个序列,能够交换k次,问交换完后的子序列最大值的最大值是多少 思路:暴力枚举每一个区间,然后每一个区间[l,r]之内的值先存在优先队列内, ...
- [Codeforces 425A] Sereja and Swaps
[题目链接] https://codeforces.com/contest/425/problem/A [算法] 枚举最终序列的左端点和右端点 , 尝试用这段区间中小的数与区间外大的数交换 时间复杂度 ...
- codeforces 425A Sereja and Swaps(模拟,vector,枚举区间)
题目 这要学习的是如何枚举区间,vector的基本使用(存入,取出,排序等),这题的思路来自: http://www.tuicool.com/articles/fAveE3 //vector 可以用s ...
- [ 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 题目链接 题意: 给定一个整数 ...
随机推荐
- calltree查看工程代码中的函数调用关系
http://blog.csdn.net/elitemouse/article/details/41680113 http://www.tinylab.org/callgraph-draw-the-c ...
- Struts2 ValueStack
一.作用 可以作为一个数据中转站,用在前台和后台数据传递 二.生命周期 ValueStack的生命周期是随着request的创建而创建,随request的销毁而销毁. 三.结构 OgnlValueSt ...
- Java基础知识强化之集合框架笔记34:List练习之集合的嵌套遍历
1. 需求: 我们班有学生,每一个学生是不是一个对象.所以我们可以使用一个集合表示我们班级的学生.ArrayList<Student> 但是呢,我们旁边是不是还有班级,每个班级是不是也是一 ...
- HTML设置固定页脚飘浮
Css /* 页脚 */.footSty{bottom: 0pt; margin: 0pt; position: fixed; width: 100%; z-index: 10 ! important ...
- My-sql #1045 - Access denied for user 'root'@'localhost' (using password: NO)
当你重装数据库后出现这个问题的时候,不要着急,首先你要去你的确定你的数据库已经成功的把服务开启了, 然后确定你的密码和账户,IP都确认的情况下, 去寻找config.inc.php 这个文件,根据配置 ...
- VsSharp:一个VS扩展开发框架(上)
上篇:设计 一.引子 自2008年起开发SSMS插件SqlSharp(er)的过程中,有一天发现多数代码都大同小异,就像这样. Commands2 commands = (Commands2)_app ...
- php中调用其他系统http接口的方法说明
使用函数: file_get_contents($url); 传入接口url及其参数:如 $url="http://192.168.1.1/test.jsp?id=1&type=2& ...
- 在eclipse下面搭建Clojure开发运行环境
打开eclipse,点击菜单栏“help->Install New Software...", 然后,点击”add“, 在Location处输入 http://ccw.cgrand.n ...
- 安装SQLServer2008后Windows防火墙上的端口开放
1.打开SQL Server 配置管理器-->SQL Server 网络配置-->XXX的协议,启用TCP/IP协议2.打开TCP/IP协议的属性,切至“IP地址”标签,拉至最下端的IPA ...
- I/O多路复用之poll
poll函数和select函数非常相似,但是函数接口不一样. #include <poll.h> int poll(struct pollfd *fdarray, unsigned lon ...