题目

题意:求任意连续序列的最大值,这个连续序列可以和其他的 值交换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. windows鼠标消息处理与键盘模拟函数

    1.鼠标坐标问题 BOOL GetWindowRect(   HWND hWnd,   LPRECT lpRect  ); RECT x;//定义一个二维数组x ::GetWindowRect(hwn ...

  2. git@oschina.net源代码管理使用日记

    git的优势: 1 可以创建分支: 2 版本控制是基于每一次提交的,而不需要考虑每次提交了多少个文件. 下载: 下载网址为:http://git-scm.com/download,根据您的操作系统选择 ...

  3. 巨大bug

    //数据结构关于课程设计--------图书馆管理系统的设计 #include <stdio.h> #include <stdlib.h> #include <strin ...

  4. 2007: [Noi2010]海拔 - BZOJ

    Description YT市是一个规划良好的城市,城市被东西向和南北向的主干道划分为n×n个区域.简单起见,可以将YT市看作一个正方形,每一个区域也可看作一个正方形.从而,YT城市中包括(n+1)× ...

  5. 1021 玛丽卡 - Wikioi

    题目描述 Description麦克找了个新女朋友,玛丽卡对他非常恼火并伺机报复. 因为她和他们不住在同一个城市,因此她开始准备她的长途旅行. 在这个国家中每两个城市之间最多只有一条路相通,并且我们知 ...

  6. hadoop 技巧

    通过--config指定不同的集群 bin/hadoop --config ./conf_time/ dfs -ls /user/rd/*/for_*/ip_table/output/ rd下是都读写 ...

  7. Atmel Studio 6.0新建项目

        使用Atmel Studio 6.0新建一个项目 连接Atmel 开发板与调试板,开发板使用的芯片是ATXMGEA128A1 注意: 以上对于开发板与调试板的连接,需要非常注意连接时线的方向, ...

  8. jQuery基于ajax实现星星评论代码

    本文实例讲述了jQuery基于ajax实现星星评论代码.分享给大家供大家参考.具体如下: 这里使用jquery模仿点评网的星星评论功能,Ajax评论模块,鼠标点击星星即可评价,下边是分数,可以点击后给 ...

  9. C# mongodb [下]

    概述 传统的关系数据库一般由数据库(database).表(table).记录(record)三个层次概念组成,MongoDB是由数据库(database).集合(collection).文档对象(d ...

  10. C++ explict 关键字

    关键字explicit可以禁止“单参数构造函数”被用于自动类型转换class Stack{explicit Stack(int size);};没有explicit的话Stack s = 40;能编译 ...