Codeforces Round #243 (Div. 2) C. Sereja and Swaps(优先队列 暴力)
题意:求任意连续序列的最大值,这个连续序列可以和其他的 值交换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(优先队列 暴力)的更多相关文章
- 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 Round #243 (Div. 2) C. Sereja and Swaps
由于n比较小,直接暴力解决 #include <iostream> #include <vector> #include <algorithm> #include ...
- Codeforces Round #243 (Div. 2) B. Sereja and Mirroring
#include <iostream> #include <vector> #include <algorithm> using namespace std; in ...
- Codeforces Round #243 (Div. 2) A. Sereja and Mugs
#include <iostream> #include <vector> #include <algorithm> #include <numeric> ...
- Codeforces Round #243 (Div. 2) A~C
题目链接 A. Sereja and Mugs time limit per test:1 secondmemory limit per test:256 megabytesinput:standar ...
- Codeforces Round #243 (Div. 2) Problem B - Sereja and Mirroring 解读
http://codeforces.com/contest/426/problem/B 对称标题的意思大概是.应当指出的,当线数为奇数时,答案是线路本身的数 #include<iostream& ...
- Codeforces Round #243 (Div. 2)——Sereja and Swaps
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u012476429/article/details/24665103 题目链接 题意: 给定一个整数 ...
- Codeforces Round #243 (Div. 2)——Sereja and Table
看这个问题之前,能够先看看这个论文<一类算法复合的方法>,说白了就是分类讨论,可是这个思想非常重要 题目链接 题意: 首先给出联通块的定义:对于相邻(上下和左右)的同样的数字视为一个联通块 ...
- Codeforces Round #243 (Div. 1)——Sereja and Two Sequences
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u012476429/article/details/24798219 题目链接 题意:给两个长度分别 ...
随机推荐
- nodejs小问题:express不是内部或外部命令(转载)
安装express之后发现居然提示express不是内部或外部命令. 工具/原料 Node.js安装包 方法/步骤 1 首先下载Node.js安装包,此处我用的是官方最新的v0.10.27 32位版: ...
- git@oschina.net源代码管理使用日记
git的优势: 1 可以创建分支: 2 版本控制是基于每一次提交的,而不需要考虑每次提交了多少个文件. 下载: 下载网址为:http://git-scm.com/download,根据您的操作系统选择 ...
- jquery获取标签内容,编辑内容
一.获取页面元素 三种方式获取页面中元素的内容. input标签使用:.val()获取 标签下的html及文本内容:.html() 仅获取标签下的纯文本内容:.text() <head> ...
- [设计模式] 11 享元模式 Flyweight
转 http://blog.csdn.net/wuzhekai1985/article/details/6670298 问题 在面向对象系统的设计何实现中,创建对象是最为常见的操作.这里面就有一个问题 ...
- linux系统进程的内存布局
内存管理模块是操作系统的心脏:它对应用程序和系统管理非常重要.今后的几篇文章中,我将着眼于实际的内存问题,但也不避讳其中的技术内幕.由于不少概念是通用的,所以文中大部分例子取自32位x86平台的Lin ...
- POJ 3104
Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7959 Accepted: 2014 Descriptio ...
- POJ 3292
Semi-prime H-numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7059 Accepted: 3 ...
- C#委托及事件
转载:http://www.cnblogs.com/warensoft/archive/2010/03/19/1689806.html C#委托及事件 在C#中,委托(delegate)是一种引用类型 ...
- Project Euler 87 :Prime power triples 素数幂三元组
Prime power triples The smallest number expressible as the sum of a prime square, prime cube, and pr ...
- A. Counting Kangaroos is Fun(贪心)
#include<stdio.h> #include<algorithm> using namespace std; ]; int main() { int i,n,high; ...