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 题目链接 题意:给两个长度分别 ...
随机推荐
- WPF中使用ValueConverter来实现“范围条件触发器”
在WPF中,我们知道界面层可以通过Trigger触发器实现“条件”——“赋值”的功能 属性触发器Property Trigger:当Dependency Property的值发生改变时触发.数据触发器 ...
- LintCode-Word Search II
Given a matrix of lower alphabets and a dictionary. Find all words in the dictionary that can be fou ...
- html+css学习笔记 [基础1]
---------------------------------------------------------------------------------------------------- ...
- Timer 的缺陷
java.util.Timer计时器有管理任务延迟执行("如1000ms后执行任务")以及周期性执行("如每500ms执行一次该任务").但是,Timer存在一 ...
- table 与 div 固定宽高问题
div {width:100px;height:200px;word-wrap: break-word;overflow:hidden;} 这个可以固定div的宽高,溢出内容会被剪除. table{t ...
- Unity3D 游戏开发应用篇——每日登陆(持久化类实现)
上一篇中我们实现用本地文件实现了持久化类的保存,当然小型数据用PlayerPrefs存储,或者采用XML服务器持久化也行.因为我涉及的角色类和玩家类数据比较多,加上项目要求尽量少与服务器交互,所以采用 ...
- 【redis】05Redis的常用命令及高级应用
Redis常用命令 Redis提供了非常丰富的命令,对数据库和个中数据类型进行操作, 这些命令呢,可以在Linux终端使用. 分为两大类的命令,一种是键值相关的命令,一种是服务器相关的命令, ...
- Public, Private and Protect
public 意味着在其后声明的所有成员对所有的人都可以取. private 意味着除了该类型的创建者和类的内部成员函数之外,任何人都不能存取这些成员. protect 它与private基本相似,只 ...
- POJ 2106 Boolean Expressions (布尔表达式求值)
题意:关于!,&,| 的运算,表达式中V代表true,F代表false. 思路:见代码吧,很详细了. 要注意 !!!F,!(...) 的情况. #include <iostream> ...
- Android ActionBar 关于tab的应用 以及 TabListener的方法详解
actionBar的tab标签应用以及TabListener的方法详解 package com.example.actionBarTest.actionBarTab; import android.a ...