cf428c 模拟题

这题说的是给了 n个数然后又 k次 的交换任意位置的 数字的机会  计算最长的连续子序列的和

这要撸  模拟整个 过程 并不能就是算最长的递增序列 如果只是 找最长的 和序列的 话 会存在 很多问题 在替换的时候 每一个决策
都影响着 下一个决策  这样 存在谁与谁替换 这样的状态有 200!种    那就枚举每个区间这样就可以使得
我们所用替换方法得当  因为在替换中我们进行替换是对不同区间的 操作 比如 在替换序列之内的 数字的时候 其实操作的就是不同的区间
与外面的序列进行替换的时候 操作的 是不同的 区间 这样就可以 可以知道 每个区间都是有可能成为 最大区间的

#include <iostream>
#include<cstdio>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
struct inq{
int x;
inq(int a=0){ x=a; }
bool operator <(const inq &A)const {
return x>A.x;
}
};
struct outq{
int x;
outq(int a=0){ x=a; }
bool operator <(const outq &A)const{
return x<A.x;
}
};
priority_queue<inq>In;
priority_queue<outq>Out;
int d[250],mav,GH,sum,k,n;
void jud(){
int num=k;
while(num){
bool falg=true;
int id=0,od=0,mi,mo;
if(In.size()!=1){
id=1; mi=In.top().x;
}
if(!Out.empty()){
od=1; mo=Out.top().x;
}
if(id&&od&&mi<0&&mo>0){
falg=false;
sum+=mo-mi; In.pop(); Out.pop();
}
else if(id&&mi<0){
falg=false;
sum+=-mi; In.pop();
}
else if(od&&mo>0){
falg=false;
sum+=mo; Out.pop();

}else if(od&&id&&mo>mi){falg=false;
sum+=mo-mi; Out.pop(); In.pop();
}
--num;
if(falg) break;
}
mav=sum>mav?sum:mav;
}
int main()
{
mav=-3000000;
scanf("%d%d",&n,&k);
for(int i=0;i<n;++i)
scanf("%d",&d[i]);
for(int L=0;L<=n;L++){
for(int S=0;S+L<n;++S){
sum=0;
for(int j=0;j<n;j++)
if(j>=S&&j<=L+S) { sum+=d[j];In.push(d[j]); }
else Out.push(d[j]);
jud();
while(!In.empty()) In.pop();
while(!Out.empty()) Out.pop();
}

}
printf("%d\n",mav);
return 0;
}

cf428c 模拟题,布布扣,bubuko.com

时间: 2024-08-03 10:14:12

cf428c 模拟题的相关文章

HDU 4028 The time of a day STL 模拟题

暴力出奇迹.. #include<stdio.h> #include<iostream> #include<algorithm> #include<vector> #include<cmath> #include<queue> #include<set> #include<map> using namespace std; #define ll __int64 #define N 42 ll n,m,ans;

TOJ1290 Poker Hands 模拟题

寒假期间抽空做的一道模拟题 难度不算大,把每种牌型分开处理,可以合并的步骤考虑合并. 代码比较丑陋,首次尝试Sport Programming的风格,结果搞了个不伦不类(手动笑哭) 1 #include <algorithm> 2 #include <bitset> 3 #include <cctype> 4 #include <complex> 5 #include <cstdio> 6 #include <cstring> 7 #

hdu 5641 King&#39;s Phone(暴力模拟题)

Problem Description In a military parade, the King sees lots of new things, including an Andriod Phone. He becomes interested in the pattern lock screen. The pattern interface is a 3×3 square lattice, the three points in the first line are labeled as

HDU 2414 Chessboard Dance(模拟题,仅此纪念我的堕落)

题目 模拟题也各种wa,我最近真的堕落了,,,,,智商越来越为负数了!!!!!!!! #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; char mp[10][10]; int d=-1;//0shang,1xia,2zuo,3you int x,y;//weizhi int weizhi(int i,int j) { if(mp[i][j]=='<'){x=

HDU 4930 Fighting the Landlords(扯淡模拟题)

Fighting the Landlords 大意: 斗地主....   分别给出两把手牌,肯定都合法.每张牌大小顺序是Y (i.e. colored Joker) > X (i.e. Black & White Joker) > 2 > A (Ace) > K (King) > Q (Queen) > J (Jack) > T (10) > 9 > 8 > 7 > 6 > 5 > 4 > 3. 给你8种组合:1.

锦程网考试由试题从模拟题中批量找出答案,Python

jincin的考试又来了,像往常一样会先有模拟题发下来,而考试题目几乎都在里面原题. 本来是,在考试时,把题目一题一题地在模拟题里搜,但觉得太累了. 于是写了一个Python的脚本批量查找,用到正则,由于不知道行尾是\r还是\n还是\r\n,干脆也用正则,而非split('\r')这么硬板了. 添了颜色,效果不错. Python: 效果: - 锦程网考试由试题从模拟题中批量找出答案,Python,布布扣,bubuko.com

Codeforces 48C The Race 模拟题

题目链接:点击打开链接 题意: 给定n个加油站,一辆车由A点跑到B点,每个100m有一个加油站,每开100m需要10升油. 在每个车站会检查一下油量,若车子若开不到下一个加油站则加x升油. 开始有x升油 下面给出加油的记录. 问下一次加油在哪一站.若答案唯一输出具体哪站. 油箱容量无限 思路: 水模拟.. #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h>

FZU Problem 2034 Password table (简单模拟题)

这种简单题做了好长时间,我是不是有点逗? 地址:http://acm.fzu.edu.cn/problem.php?pid=2034 不解释了,自己看吧,练手的好题 上个代码吧 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 #include <stdio.h> #include <string.h> #include <stdlib.h>

[BZOJ入门OJ2092][Noip模拟题]舞会

2092: [Noip模拟题]舞会 Time Limit: 20 Sec  Memory Limit: 256 MB Submit: 9  Solved: 5 [Submit][Status][Web Board] Description 学校举行舞会啦,一共有N个人参加,所有人站成一排,从左开始编号,最左边的人编号为1 ,最右边的为N.每个人跳舞的熟练度我们用一个整数表示,第i个人的熟练度为Ai,每次熟 练度最接近的一对相邻男女会出列跳舞,如果有多对那么最左边的那一对会先出列,请你给 出出列跳