[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 题目链接 题意: 给定一个整数 ...
随机推荐
- 零基础入门学习Python(34)--丰富的else语句及简洁的with语句
知识点 else语句的用法: 1)配合if语句 if a>b: print(a) else: print(b) 2)配合while和for循环 只在循环完成后才执行,如果循环中执行使用到brea ...
- ThinkPHP5.X PHP5.6.27-nts + Apache 通过 URL 重写来隐藏入口文件 index.php
我们先来看看官方手册给出关于「URL 重写」的参考: 可以通过 URL 重写隐藏应用的入口文件 index.php ,Apache 的配置参考: 1.http.conf 配置文件加载 mod_rewr ...
- 基础知识:if条件、while循环、for循环 相关练习
1.实现用户输入用户名和密码,当用户名为 seven 且 密码为 123 时,显示登陆成功,否则登陆失败! while True: name = input('请输入用户名:') psw = inpu ...
- stark组件之处理函数动态url构造(五)
在这个组件中有内置的4个处理函数,它们都有自己对应的url,那么它们的url是怎么构造的呢? ... urlpatterns = [ re_path('list/$', self.wrapper(se ...
- xtu summer individual 5 D - Subsequence
Subsequence Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID ...
- Leetcode 153.寻找旋转数组中的最小值
寻找旋转数组中的最小值 假设按照升序排序的数组在预先未知的某个点上进行了旋转. ( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] ). 请找出其中最小的元素. ...
- ABC077翻车实况
今天强行打一波ABC,想作为信心赛,然而= = T1 日常练习读入&输出 T2 $STL$大法好,$sqrt$保平安,我强行递推$WA$了一圈,然后罚时++ T3 woc好难啊,$n=1 ...
- 解决Codeforces访问慢的本地方案
参考: http://m.blog.csdn.net/blog/Xiangamp/42245923#
- [NOIP2006] 普及组
明明的随机数 STL真是偷懒神器 /*by SilverN*/ #include<algorithm> #include<iostream> #include<cstri ...
- redis运维相关(基本数据库命令)【十四】
-----------------------------运维相关------------------------- redis持久化,两种方式1.rdb快照方式2.aof日志方式 --------- ...