[Codeforces 425A] Sereja and Swaps
[题目链接]
https://codeforces.com/contest/425/problem/A
[算法]
枚举最终序列的左端点和右端点 , 尝试用这段区间中小的数与区间外大的数交换
时间复杂度 : O(N^3logN)
[代码]
- #include<bits/stdc++.h>
- using namespace std;
- const int MAXN = ;
- const int inf = 2e9;
- int n , k;
- int a[MAXN],b[MAXN],value[MAXN];
- template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
- template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
- template <typename T> inline void read(T &x)
- {
- T f = ; x = ;
- char c = getchar();
- for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
- for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
- x *= f;
- }
- int main()
- {
- read(n); read(k);
- for (int i = ; i <= n; i++) read(value[i]);
- int ans = -inf;
- for (int i = ; i <= n; i++)
- {
- for (int j = i; j <= n; j++)
- {
- int la = , lb = , cnt = ;
- for (int x = ; x <= n; x++)
- {
- if (x >= i && x <= j)
- {
- a[++la] = value[x];
- cnt += value[x];
- } else
- b[++lb] = value[x];
- }
- sort(a + ,a + la + );
- sort(b + ,b + lb + ,greater<int>());
- for (int x = ; x <= min(la,min(lb,k)); x++)
- {
- if (b[x] - a[x] > )
- cnt += b[x] - a[x];
- else break;
- }
- ans = max(ans,cnt);
- }
- }
- printf("%d\n",ans);
- return ;
- }
[Codeforces 425A] Sereja and Swaps的更多相关文章
- Codeforces 425A Sereja and Swaps(暴力枚举)
题目链接:A. Sereja and Swaps 题意:给定一个序列,能够交换k次,问交换完后的子序列最大值的最大值是多少 思路:暴力枚举每一个区间,然后每一个区间[l,r]之内的值先存在优先队列内, ...
- codeforces 425A Sereja and Swaps(模拟,vector,枚举区间)
题目 这要学习的是如何枚举区间,vector的基本使用(存入,取出,排序等),这题的思路来自: http://www.tuicool.com/articles/fAveE3 //vector 可以用s ...
- codeforces C. Sereja and Swaps
http://codeforces.com/contest/426/problem/C 题意:找出连续序列的和的最大值,可以允许交换k次任意位置的两个数. 思路:枚举区间,依次把区间内的比较小的数换成 ...
- [ An Ac a Day ^_^ ] CodeForces 426C Sereja and Swaps 优先队列
题意: 给你一个有n个数的序列 取一个区间 这个区间内的数可以与区间外的值交换k次 问这样的区间最大值是多少 思路: 看数据是200 时间复杂度O(n*n) 应该可以暴力 顺便学习一下优先队列 枚举区 ...
- 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 339]E. Three Swaps
[codeforces 339]E. Three Swaps 试题描述 Xenia the horse breeder has n (n > 1) horses that stand in a ...
- Codeforces Round #243 (Div. 2) C. Sereja and Swaps
由于n比较小,直接暴力解决 #include <iostream> #include <vector> #include <algorithm> #include ...
- Codeforces Round #243 (Div. 2) C. Sereja and Swaps(优先队列 暴力)
题目 题意:求任意连续序列的最大值,这个连续序列可以和其他的 值交换k次,求最大值 思路:暴力枚举所有的连续序列.没做对是因为 首先没有认真读题,没看清交换,然后,以为是dp或者贪心 用了一下贪心,各 ...
- Codeforces Round #243 (Div. 2)——Sereja and Swaps
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u012476429/article/details/24665103 题目链接 题意: 给定一个整数 ...
随机推荐
- 零基础入门学习Python(23)--递归:这帮小兔崽子
知识点 我们都知道兔子繁殖能力是惊人的,如下图: 我们可以用数学函数来定义: 假设我们需要求出经历了20个月后,总共有多少对小兔崽子? 迭代实现 def fab(n): n1 = 1 n2 = 1 n ...
- crm项目之stark组件前戏(二)
stark组件的设计主要来源于django中admin的功能,在django admin中只需要将模型表进行注册,就可以在页面对该表进行curd的动作,那么django admin是如何做的呢? 在d ...
- Anaconda基本用法
Anaconda基本用法 conda info --envs/(-e) // 查看当前的环境变量 conda create -n py36(环境的名称,随意) python=3.6(指定版本) // ...
- //……关于promise
什么是promise? promise 翻译成中文的意思是 "承诺" ,一个承诺说出去了说明他是进行中的,承诺兑现了代表成功,没有兑现代表失败了. promise 对象的状态一旦发 ...
- 关于c# .net爬虫
刚开始听到爬虫这两个字眼的时候感觉挺稀奇的,之前并没有接触过爬虫,正好这会手上没事,于是便百度了一下. 1.网络爬虫(又被称为网页蜘蛛,网络机器人,在FOAF社区中间,更经常的称为网页追逐者),是一种 ...
- Eclipse Myeclipse 设定文件的默认打开方式
Eclipse Myeclipse 设定文件的默认打开方式 菜单:Window -> Preferences -> General -> Editors -> File A ...
- JS数组添加元素的三种方式
1.push() 结尾添加 数组.push(元素) 参数 描述 newelement1 必需.要添加到数组的第一个元素. newelement2 可选.要添加到数组的第二个元素. newelement ...
- HDU-1163Eddy's digital Roots,九余定理的另一种写法!
下午做了NYOJ-424Eddy's digital Roots后才正式接触了九余定理,不过这题可不是用的九余定理做的.网上的博客千篇一律,所以本篇就不发篇幅过多介绍九余定理了: 但还是要知道什么是九 ...
- fzu 2113 数位dp
#include<stdio.h> #include<string.h> #define N 20 #define ll __int64 ll dp[N][N];//最多记忆4 ...
- 【NOIP2016】天天爱跑步(树上差分)
题意: 小c同学认为跑步非常有趣,于是决定制作一款叫做<天天爱跑步>的游戏.?天天爱跑步?是一个养成类游戏,需要 玩家每天按时上线,完成打卡任务.这个游戏的地图可以看作一一棵包含 N个结点 ...