题目

这要学习的是如何枚举区间,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,枚举区间)的更多相关文章

  1. Codeforces 425A Sereja and Swaps(暴力枚举)

    题目链接:A. Sereja and Swaps 题意:给定一个序列,能够交换k次,问交换完后的子序列最大值的最大值是多少 思路:暴力枚举每一个区间,然后每一个区间[l,r]之内的值先存在优先队列内, ...

  2. [Codeforces 425A] Sereja and Swaps

    [题目链接] https://codeforces.com/contest/425/problem/A [算法] 枚举最终序列的左端点和右端点 , 尝试用这段区间中小的数与区间外大的数交换 时间复杂度 ...

  3. codeforces C. Sereja and Swaps

    http://codeforces.com/contest/426/problem/C 题意:找出连续序列的和的最大值,可以允许交换k次任意位置的两个数. 思路:枚举区间,依次把区间内的比较小的数换成 ...

  4. [ An Ac a Day ^_^ ] CodeForces 426C Sereja and Swaps 优先队列

    题意: 给你一个有n个数的序列 取一个区间 这个区间内的数可以与区间外的值交换k次 问这样的区间最大值是多少 思路: 看数据是200 时间复杂度O(n*n) 应该可以暴力 顺便学习一下优先队列 枚举区 ...

  5. 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 ...

  6. [codeforces 339]E. Three Swaps

    [codeforces 339]E. Three Swaps 试题描述 Xenia the horse breeder has n (n > 1) horses that stand in a ...

  7. Python中模拟enum枚举类型的5种方法分享

    这篇文章主要介绍了Python中模拟enum枚举类型的5种方法分享,本文直接给出实现代码,需要的朋友可以参考下   以下几种方法来模拟enum:(感觉方法一简单实用) 复制代码代码如下: # way1 ...

  8. PJ可能会考的模拟与枚举-自学教程

    PJ可能会考的模拟与枚举-自学教程 文/Pleiades_Antares 之前学校里看一个小可爱复习的时候偷偷听来着XD 简单记了一下重点吧,希望能对看官您有所帮助XD 以下⬇️是几个复习时讲过的题, ...

  9. CodeForces.158A Next Round (水模拟)

    CodeForces.158A Next Round (水模拟) 题意分析 校赛水题的英文版,坑点就是要求为正数. 代码总览 #include <iostream> #include &l ...

随机推荐

  1. Android 使用Fragment,ViewPagerIndicator 制作csdn app主要框架

    转载  转载请注明出处:http://blog.csdn.net/lmj623565791/article/details/23513993 本来准备下载个CSDN的客户端放手机上,没事可以浏览浏览资 ...

  2. WPF实现3D翻转的动画效果

    1.前端代码实现 1.1 原理见代码注析 <Grid MouseDown="Grid_MouseDown"> <Viewport3D> <Viewpo ...

  3. 嵌入式中的 *(volatile unsigned int *)0x500 解释

    C语言中*(volatile unsigned int *)0x500的解释: 如下: (unsigned int *)0x500:将地址0x500强制转化为int型指针*(unsigned int ...

  4. Android--PullToRefreshListView 的简单使用

    原文:  http://blog.csdn.net/lmj623565791/article/details/38238749; pull-to-refresh对ListView进行了封装,叫做:Pu ...

  5. hdu 5146 Sequence

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5146 Sequence Description Today we have a number sequ ...

  6. Ubuntu 修改用户密码与启动root账号

    passwd sban 修改当前帐号 sudo passwd root 修改root帐号 修改/etc/ssh/sshd_config,改: PermitRootLogin without-passw ...

  7. Eclipse Indigo 3.7.0 安装GIT插件提示 requires 'bundle org.eclipse.team.core(转)

    文章参考来源:http://showlike.iteye.com/blog/1958538 错误提示: Cannot complete the install because one or more ...

  8. HTML a 标签 下载 apk 文件

    代码:   <a href="http://www.abc2016.com/phone_Client/shouji.apk" class="download_inp ...

  9. 3. 戏说VHDL之入门游戏一:流水灯

    一.   流水灯 1.1流水灯原理 流水灯是每个学电子的入门“游戏” ,示意图如图1,其原理极其简单,但是可玩性却极强,可以就8个LED写出不同花样的程序.在1.2中我们列出两个不同思路的代码作为VH ...

  10. [转]log4net 使用指南

    声明:本文内容主要译自Nauman Leghari的Using log4net,亦加入了个人的一点心得(节3.1.4). 请在这里下载示例代码 1           简介 1.1          ...