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 题目链接 题意: 给定一个整数 ...
随机推荐
- 网络子系统43_ip选项预处理
//选项格式: // 1.type中指示该选项在分片时是否需要被拷贝 // 2.ptr从1算起,1为type的位置 // 3.len不包括type字段,其余都包括(len,ptr,选项内容) //ty ...
- Maven实现Web应用集成測试自己主动化 -- 部署自己主动化(WebTest Maven Plugin)
上篇:Maven实现Web应用集成測试自己主动化 -- 測试自己主动化(WebTest Maven Plugin) 之前介绍了怎样在maven中使用webtest插件实现web的集成測试,这里有个遗留 ...
- 我的docker 使用笔记
0 容器启动 docker run image_name(镜像名称) echo "hello word" 1 启动容器 退出后 重新进入 方法一 sudo docker exec ...
- [AngularJS + Webpack] Requiring Templates
With Angular, most of the time you're specifying a templateUrl for your directives and states/routes ...
- SQL Server 事务、异常
转自: http://www.cnblogs.com/moss_tan_jun/archive/2011/11/26/2263988.html 事务 在数据库中有时候需要把多个步骤的指令当作一个整 ...
- PL/SQL Select into 异常处理
在使用select into 为变量赋值时,如果变量是集合类型,不会产生异常,而如果是基本类型或记录类型,则会报异常. 异常产生了怎么办?当然是捕获并处理啦. 对于普通的代码块来说,在代码块的结尾处理 ...
- C#--Session用完如何清除
Session.Abandon();//清除全部Session//清除某个SessionSession["UserName"] = null;Session.Remove(&quo ...
- 自己做的demo--关于HashMap
package com.pb.collection; import java.util.HashMap; import java.util.Iterator; import java.util.Map ...
- TOKEN的保存与验证
Token主要为了防止非本页数据的提交,防止重复提交. /** * * 保存TOKEN信息 * */ public void saveToken() { //此处生成md5串 string md5 = ...
- jquery ui 插件------------------------->sortable
<!doctype html><html lang="en"><head> <meta charset="utf-8" ...