[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 题目链接 题意: 给定一个整数 ...
随机推荐
- [安装] mac安装PHP7经历
背景 前几天在mac上跑workrman,由于workerman需要开启多个进程,多进程需要pcntl扩展的支持,我之前那个brew安装的php71没有这个扩展,就直接卸载了php71,然后想下载源码 ...
- 配置python3 项目环境
安装python3 安装仓库软件 sudo apt-get install software-properties-common python-software-properties 添加仓库 sud ...
- PHP:获取用户IP
文章来源:http://www.cnblogs.com/hello-tl/p/7685263.html //获取用户ip(外网ip 服务器上可以获取用户外网Ip 本机ip地址只能获取127.0.0.1 ...
- Broadcasting
目录 Broadcasting Key idea How to understand? Why broadcasting? Broadcastable? Broadcast VS Tile Broad ...
- 59. Spring Boot Validator校验【从零开始学Spring Boot】
大纲: (1) 入门例子: (2) 国际化: (3) 在代码中添加错误信息: (1) 入门例子: Validator主要是校验用户提交的数据的合理性的,比如是否为空了,密码长度是否大于6位,是否是纯数 ...
- 「CodePlus 2017 11 月赛」大吉大利,晚上吃鸡!
n<=50000,m<=50000的图,给s和t,问有多少点对$(a,b)$满足 嗯. 不会. 首先最短路DAG造出来,然后两个条件转述一下:条件一,$N_a$表示从s到t经过a的路径,$ ...
- cogs——555. 网络探测
555. 网络探测 ★☆ 输入文件:ping.in 输出文件:ping.out 简单对比时间限制:1 s 内存限制:128 MB [问题描述] 当出现网络故障时,我们经常使用“p ...
- codevs——6220 ZHR吃好吃的
6220 ZHR吃好吃的 时间限制: 1 s 空间限制: 1000 KB 题目等级 : 白银 Silver 题解 查看运行结果 题目描述 Description 有一个人名字叫ZHR, ...
- Ubuntu 16.04使用sudo apt-get -f install解决依赖时的注意事项(重点)
注意:在觉得软件依赖时,一般使用sudo apt-get -f install,但是也是非常危险的,尤其时一些软件需要删除某些依赖时,会导致原有安装的软件全部卸载.所以使用此命令时要时刻注意输出的这条 ...
- SystemTap 学习笔记 - 安装篇
https://segmentfault.com/a/1190000000671438 在安装前,需要知道下自己的系统环境,我的环境如下: uname -r 2.6.18-308.el5 Linux ...