codeforces 425A Sereja and Swaps(模拟,vector,枚举区间)
这要学习的是如何枚举区间,vector的基本使用(存入,取出,排序等),这题的思路来自:
http://www.tuicool.com/articles/fAveE3
//vector 可以用sort排序:sort(ve.begin(),ve.end());
//下标从0开始,内部元素可以用vec[i]这样像数组一样表示
//插入用push_back()
//个数用size() #include <cstdio>
#include<iostream>
#include <cstring>
#include <algorithm>
#include<vector>
using namespace std;
vector<int>ve;
vector<int>vec;
int main() {
int n,kk;
int a[];
cin >> n>>kk;
for(int i=;i<n;i++)
cin>>a[i];
int maxx=-;
for(int i=;i<n;i++)
{
for(int j=i+;j<=n;j++)
{
ve.clear();
vec.clear();
int sum=a[i];
ve.push_back(a[i]);
maxx=maxx>sum? maxx:sum; for(int k=i+;k<j;k++)
{
sum+=a[k];
ve.push_back(a[k]);
}
for(int k=;k<i;k++)
{
vec.push_back(a[k]);
}
for(int k=j;k<n;k++)
{
vec.push_back(a[k]);
}
sort(ve.begin(),ve.end());
sort(vec.begin(),vec.end());
int l1=ve.size();
int l2=vec.size();
for(int k=;k<kk&&k<l1&&k<l2;k++)
{
int x=vec[l2-k-];
int y=ve[k];
if(x-y<=)break;
sum=sum+x-y;
}
maxx=maxx>sum? maxx:sum;
}
}
cout << maxx<<endl;
return ;
}
codeforces 425A Sereja and Swaps(模拟,vector,枚举区间)的更多相关文章
- 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 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 ...
 - Python中模拟enum枚举类型的5种方法分享
		
这篇文章主要介绍了Python中模拟enum枚举类型的5种方法分享,本文直接给出实现代码,需要的朋友可以参考下 以下几种方法来模拟enum:(感觉方法一简单实用) 复制代码代码如下: # way1 ...
 - PJ可能会考的模拟与枚举-自学教程
		
PJ可能会考的模拟与枚举-自学教程 文/Pleiades_Antares 之前学校里看一个小可爱复习的时候偷偷听来着XD 简单记了一下重点吧,希望能对看官您有所帮助XD 以下⬇️是几个复习时讲过的题, ...
 - CodeForces.158A Next Round (水模拟)
		
CodeForces.158A Next Round (水模拟) 题意分析 校赛水题的英文版,坑点就是要求为正数. 代码总览 #include <iostream> #include &l ...
 
随机推荐
- m3u8
			
audo apt-get install pkg-configsudo apt-get install automake autoconf m4 libtool sudo apt-get instal ...
 - 怎么解决/bin/sh: arm-linux-gcc: not found make
			
1.arm-linux-gcc 环境变量没有设,所以找不到这个编译器 在/etc/profile里添加arm-linux-gcc的存放路径 sudo -s gedit /etc/profile 编 ...
 - c++基础(一):数据类型和结构
			
1.map map<int, int> rankDict;//定义map rankDict[1] = 5; rankDict[2] = 6;//map赋值 int dictSize = r ...
 - python数组的使用
			
python数组的使用 2010-07-28 17:17 1.Python的数组分三种类型:(1) list 普通的链表,初始化后可以通过特定方法动态增加元素.定义方式:arr = [元素] (2) ...
 - Mac下如何显示隐藏文件/文件夹_百度经验
			
在应用程序里打开终端, cd 你的文件夹名 ls -a 即可显示该文件夹下的所有隐藏文件 如果你想打开整个系统的隐藏文件可以在终端下输入以下命令: defaults write com.apple ...
 - Linux 编辑器
			
vim编辑器 vi作为Unix上的一个编辑器,一直广受欢迎.之后GUN将其移植到开源世界中,经过开发人员对其进行了改善,被称为vi improved,就是现在的vim.为了方便使用,几乎所有的Linu ...
 - 条款24:若所有的函数参数可能都需要发生类型转换才能使用,请采用non-member函数
			
假设有一个有理数类Rational,有一个计算有理数乘法的成员函数operator*,示例如下: #include <iostream> class Rational { public: ...
 - 函数 swift
			
func add(a:Int,b:Int)->Int { return a+b }
 - Netsharp快速入门(之6) 基础档案(创建导航菜单)
			
作者:秋时 杨昶 时间:2014-02-15 转载须说明出处 1.1 创建导航菜单 1.在Demo节点下,录入路径名称,并在下方录入两个导航页签名 2.建立分类,只要填路径名 3.双击基 ...
 - [转]Eclipse遇到的常见问题
			
1. 提示:“Setting build path” has encountered a problem,Could not write file D:\\workspace\demo\.class ...