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 题目链接 题意:给两个长度分别 ...
随机推荐
- C# Windows - 创建控件
VS提供了一个项目类型Windows Control Library,使用它可以创建自己的控件. 可以开发两种不同类型的自定义控件: 用户或组合控件:这种控件是根据现有控件的功能创建一个新控件.这类控 ...
- C++(MFC)
C++(MFC) 1.关联变量(与控件关联): (1)一组单选按钮:需要将第一个单选按钮的Group选项设为true,则单选按钮就为一组(组框为标示作用).选中第一个则为0,第二个为1,依次类推(P2 ...
- 登录超时自动退出,计算时间差-b
// 此方法适用于所有被创建过的controller,且当前controller生命周期存在,如有错误的地方望大神斧正 // 说一下我们的需求和实现原理,需求:在点击home键退出但没有滑飞它,5分 ...
- Android keyevent 中的各个值
Android keyevent 中的各个值,在使用adb shell input 的时候用得到. 是从http://blog.csdn.net/huiguixian/article/details/ ...
- json 说明书
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式. 易于人阅读和编写.同时也易于机器解析和生成. 它基于JavaScript Programming Lan ...
- PVPGN 暗黑破坏神2 1.11b战网配置问题汇总
写了第一篇配置指南之后,很多人向我咨询有关战网搭建的问题.于是觉得很有必要把若干常见的问题,和常用的进阶配置汇总一下,以方便更多人. 1.游戏版本和PVPGN与D2GS版本的问题. PVPGN建议选择 ...
- 双倍边距bug
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- BZOJ 1143: [CTSC2008]祭祀river 最大独立集
题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=1143 题解: 给你一个DAG,求最大的顶点集,使得任意两个顶点之间不可达. 把每个顶点v ...
- 【BZOJ】【2154】Crash的数字表格
莫比乌斯反演 PoPoQQQ讲义第4题 题解:http://www.cnblogs.com/jianglangcaijin/archive/2013/11/27/3446169.html 感觉两次sq ...
- PhotoshopCS4轻松将PSD分层导出为Png分层
大家在网上都下载过PSD分层素材,有时候想把素材分层导出,以往做法是一层一层导出,可是这样效率太低,其实利用PS自带功能可以轻松导出PNG分层. 我们先打开一个PSD文件. 文件有7个图层,分 ...