题目

题意:求任意连续序列的最大值,这个连续序列可以和其他的 值交换k次,求最大值

思路:暴力枚举所有的连续序列。没做对是因为 首先没有认真读题,没看清交换,然后,以为是dp或者贪心

用了一下贪心,各种bug不对。

这次用了一下优先队列,以前用的不多,看这个博客又学了一下

AC代码:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
using namespace std;
const int maxn = +; struct node
{
int x;
bool operator < (const node &tmp)const
{
return x > tmp.x;
}
};
int main()
{
int a[maxn], i, j, l;
int n, k, ans, t2, sum, t;
while(cin>>n>>k)
{
for(i = ; i < n; i++)
cin>>a[i];
ans = a[]; for(i = ; i < n; i++)
for(j = i; j < n; j++)
{
priority_queue<int>Max;
priority_queue<node>Min;
sum = ;
for(l = ; l < i; l++)
Max.push(a[l]);
for(l = j+; l < n; l++)
Max.push(a[l]);
for(l = i; l <= j; l++)
{
Min.push((node){a[l]});
sum += a[l];
} t2 = k;
while(t2 && !Max.empty() && Max.top() > Min.top().x) //这要先判空,编译的时候错了一下
{
t2--;
sum -= Min.top().x;
sum += Max.top();
t = Max.top();
Max.pop();
Max.push(Min.top().x);
Min.pop();
Min.push((node){t});
}
if(sum > ans)
ans = sum;
}
cout<<ans<<endl;
}
return ;
}

Codeforces Round #243 (Div. 2) C. Sereja and Swaps(优先队列 暴力)的更多相关文章

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

  2. Codeforces Round #243 (Div. 2) C. Sereja and Swaps

    由于n比较小,直接暴力解决 #include <iostream> #include <vector> #include <algorithm> #include ...

  3. Codeforces Round #243 (Div. 2) B. Sereja and Mirroring

    #include <iostream> #include <vector> #include <algorithm> using namespace std; in ...

  4. Codeforces Round #243 (Div. 2) A. Sereja and Mugs

    #include <iostream> #include <vector> #include <algorithm> #include <numeric> ...

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

    题目链接 A. Sereja and Mugs time limit per test:1 secondmemory limit per test:256 megabytesinput:standar ...

  6. Codeforces Round #243 (Div. 2) Problem B - Sereja and Mirroring 解读

    http://codeforces.com/contest/426/problem/B 对称标题的意思大概是.应当指出的,当线数为奇数时,答案是线路本身的数 #include<iostream& ...

  7. Codeforces Round #243 (Div. 2)——Sereja and Swaps

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u012476429/article/details/24665103 题目链接 题意: 给定一个整数 ...

  8. Codeforces Round #243 (Div. 2)——Sereja and Table

    看这个问题之前,能够先看看这个论文<一类算法复合的方法>,说白了就是分类讨论,可是这个思想非常重要 题目链接 题意: 首先给出联通块的定义:对于相邻(上下和左右)的同样的数字视为一个联通块 ...

  9. Codeforces Round #243 (Div. 1)——Sereja and Two Sequences

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u012476429/article/details/24798219 题目链接 题意:给两个长度分别 ...

随机推荐

  1. 【BZOJ 3504】[Cqoi2014]危桥

    Description Alice和Bob居住在一个由N座岛屿组成的国家,岛屿被编号为0到N-1.某些岛屿之间有桥相连,桥上的道路是双 向的,但一次只能供一人通行.其中一些桥由于年久失修成为危桥,最多 ...

  2. c++ 格式化printf

    类型为uint64_t的变量,使用printf进行打印时,需要区分操作系统: 64位系统:使用%ld 32位系统:使用%llu #include<stdio.h>#include < ...

  3. 我的第一个python爬虫程序

    程序用来爬取糗事百科上的图片的,程序设有超时功能,具有异常处理能力 下面直接上源码: #-*-coding:utf-8-*- ''' Created on 2016年10月20日 @author: a ...

  4. EntityFrame6在本地可以正常使用,部署到IIS后报异常(Additional information: The underlying provider failed on Open.)

    异常详细:An exception of type 'System.Data.Entity.Core.EntityException' occurred in EntityFramework.SqlS ...

  5. Linux 命令整理 —— 基本操作

    1.ls 目录列举(dir) 一般我们这么写: ls 列举当前目录的所有文件,如果文件很多的话,这么看很复杂.我们可以加关键字,例如我们要看包含xml的全部文件. ls *xml* 如果这个时候,我们 ...

  6. HDU 2821 Pusher

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2821 首先,题目描述给的链接游戏很好玩,建议先玩几关,后面越玩越难,我索性把这道题A了,也就相当于通关 ...

  7. POJ 3579

    Median Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3528   Accepted: 1001 Descriptio ...

  8. hdu 1905 小数化分数2

    ;}

  9. 解决Unable to load R3 module ...VBoxDD.dll (VBoxDD):GetLastError=1790

    解决Unable to load R3 module ...VBoxDD.dll (VBoxDD):GetLastError=1790 参考文章:http://blog.sina.com.cn/s/b ...

  10. 【转】Cygwin访问Windows驱动器

    From:http://www.cygwin.cn/site/info/show.php?IID=1000 由于自己的项目需要使用Linux内核,所以自己在windows下安装了一个Linux虚拟机! ...