Sereja and Swaps

题目描述:

这个题目讲述的是,输入一个包含n个数的数列,然后对这个数列,最多可以进行k个对任意两个数的交换操作,然后问我们操作完后,这个数列的最大连续子序列的和是多少。

题目分析:

这个题目我们可以暴力枚举一个区间出来,为了使这个区间和最大,我们需要将这个区间内的k个最小的数与这个区间外的k个最大的数进行交换,我们将这些可能区间全部枚举出来,最大的区间和便是答案。

代码:

#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <cstdlib>
#include <stdlib.h>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <cstring>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <deque>
#define reg register
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define lowbit(x) (x&(-x))
using namespace std;
const int Maxn=205;
int a[Maxn],b[Maxn],c[Maxn],sum[Maxn];
bool cmp(int a,int b)
{return a>b;
}
int main()
{int n,k,ans=-INF;scanf("%d%d",&n,&k);for (reg int i=1;i<=n;i++){scanf("%d",&a[i]);sum[i]=sum[i-1]+a[i];ans=max(ans,a[i]);}for (reg int i=1;i<=n;i++){for (reg int j=i;j<=n;j++){int t=sum[j]-sum[i-1],l1=0,l2=0;for (reg int q=i;q<=j;q++) b[++l1]=a[q];for (reg int q=1;q<i;q++) c[++l2]=a[q];for (reg int q=j+1;q<=n;q++) c[++l2]=a[q];sort(b+1,b+l1+1);sort(c+1,c+l2+1,cmp);int k1=1,k2=1;for (;c[k2]>b[k1] && k1<=k && k2<=k && k1<=l1 && k2<=l2;k1++,k2++) t+=c[k2]-b[k1];ans=max(ans,t);}}printf("%d\n",ans);return 0;
}

Sereja and Swaps相关推荐

  1. Codeforces Round #243 (Div. 2) A~C

    题目链接 A. Sereja and Mugs time limit per test:1 second memory limit per test:256 megabytes input:stand ...

  2. Codeforces 题目合集+分类+代码 【Updating...】【361 in total】

    961A - Tetris                                                模拟                                      ...

  3. UVA Mapping the Swaps

    题目例如以下: Mapping the Swaps  Sorting an array can be done by swapping certain pairs of adjacent entrie ...

  4. Sereja and Brackets CodeForces - 380C (树状数组+离线)

    Sereja and Brackets 题目链接: CodeForces - 380C Sereja has a bracket sequence s1, s2, ..., *s**n, or, in ...

  5. Sereja and Brackets CodeForces - 380C (线段树+分治思路)

    Sereja and Brackets 题目链接: CodeForces - 380C Sereja has a bracket sequence s1, s2, ..., *s**n, or, in ...

  6. Two Arrays And Swaps CodeForces - 1353B(贪心+分类)

    题意: 给定两个数组,你可以交换 k 次 两个数组的元素,问最后 a 数组的和最大可以是多少? 题目: You are given two arrays a and b both consisting ...

  7. C - Swaps 2(树状数组,思维)

    C - Swaps 2 给定两个长度为nnn的数组A,BA, BA,B,我们可以进行若干次如下操作,使AAA变成BBB, 选定i<ni < ni<n,将aia_iai​减小111,将 ...

  8. codeforces1455 D. Sequence and Swaps

    昨天晚上巨困,就没有打,今天课间的时候就看了一下D题,发现好像可以瞎搞,于是吃完饭就写了一下,调过样例一次就A了qaq. D. Sequence and Swaps 枚举+贪心 由于数据范围n≤500 ...

  9. Two Strings Swaps(CF-1006D)

    Problem Description You are given two strings a and b consisting of lowercase English letters, both ...

最新文章

  1. sap系统工单关闭_什么样的系统算是坑
  2. linux驱动中printk的使用注意事项
  3. (*p)++和*(p++)和*p++的区别
  4. 《剑指offer》c++版本 6.从尾到头打印链表
  5. C语言再学习 -- 文件
  6. Omi框架学习之旅 - 通过对象实例来实现组件通讯 及原理说明
  7. 语音媒体和信令的测试软件,IP多媒体子系统信令分析工具的设计与实现
  8. CentOs7相对于CentOs6的常用命令变化
  9. Selenium之前世今生
  10. HTML5中的绘图SVG VS Canvas
  11. 协方差与相关系数介绍
  12. CSS 发明者 Håkon Wium Lie 访谈--csdn zhangxin09
  13. 持续集成(Continous Integration)
  14. 一:部署harbor镜像仓库
  15. 芯动科技2023校招 FPGA岗位笔试
  16. 计算机取消uefi启动项,如何使用老毛桃winpe删除或添加UEFI BIOS启动项?
  17. 一幅图片引发的离婚大战
  18. 第二证券|监管层紧盯内幕交易 市场生态持续改善
  19. 跨六服务器维护方案,1月17日 早4点跨区2、跨区5、跨区6停机维护公告 - 地下城与勇士掌游宝...
  20. java word搜索,实战 | Java读取Word,包含表格!

热门文章

  1. office2010安装出现错误1935的解决方法
  2. build-essential unmet dependencies 有未满足依赖 解决办法
  3. PR软件——音频变音(机器音)
  4. centos7的scp命令_Linux命令-CentOS7安装scp命令,进行mac与Linux之间的文件上传下载...
  5. 在Linux中传输文件/目录的scp命令
  6. 小白对于Linux的学习
  7. win7下安装配置opengrok
  8. IT男最新躺枪:武汉恋爱培训班教搭讪女孩技巧 学员多为IT男
  9. Typora-PicGo-SMMS图床(Mac电脑和windows电脑)
  10. 【高等数学】去心邻域与邻域的意义