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

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

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

cf428c 模拟题的更多相关文章

  1. poj 1008:Maya Calendar(模拟题,玛雅日历转换)

    Maya Calendar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 64795   Accepted: 19978 D ...

  2. poj 1888 Crossword Answers 模拟题

    Crossword Answers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 869   Accepted: 405 D ...

  3. CodeForces - 427B (模拟题)

    Prison Transfer Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Sub ...

  4. sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)

    The Android University ACM Team Selection Contest Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里 ...

  5. 全国信息学奥林匹克联赛 ( NOIP2014) 复赛 模拟题 Day1 长乐一中

    题目名称 正确答案  序列问题 长途旅行 英文名称 answer sequence travel 输入文件名 answer.in sequence.in travel.in 输出文件名 answer. ...

  6. UVALive 4222 Dance 模拟题

    Dance 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&pag ...

  7. cdoj 25 点球大战(penalty) 模拟题

    点球大战(penalty) Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/2 ...

  8. Educational Codeforces Round 2 A. Extract Numbers 模拟题

    A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...

  9. URAL 2046 A - The First Day at School 模拟题

    A - The First Day at SchoolTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...

随机推荐

  1. shell脚本技巧记录

    2014/4/9 shell脚本变量处理: ${varible##*string} //从左向右截取最后一个string后的字符串 ${varible#*string} //从左向右截取第一个stri ...

  2. CentOS 安装apache

    yum 安装apache yum –y install httpd 设置开机启动 chkconfig --levels 235 httpd on 启动 /etc/init.d/httpd start ...

  3. Springmvc配置文件application.xml 和 spring-servlet.xml

    文章来源:http://blog.csdn.net/tengdazhang770960436/article/details/48395885 1.SpringMVC 的配置分为两部分 applica ...

  4. Elasticsearch-mapper 基于注解方式生成mapping(2.0以上)

    Elasticsearch生成mapping的方式上有多种方式,我们可以把mapping做成配置文件,也可以用spring-data-elasticsearch基于注解生成. 在基于注解生成这种方式上 ...

  5. css层叠样式优先级总结

    虽然学前端最刚开始就是html+css,一直因为这些看起来太简单就没有什么总结,不过看似很简单的东西,研究起来也深不可测,问起来js可能回答的头头是道,css这么简单的东西,其中一个优先级的问题就能难 ...

  6. mvc 实现超时弹窗后跳转

    为了实现保持登录状态,可以用cookie来解决这一问题 假设过期时间为30分钟,校验发生在服务器,借助过滤器,可以这样写 public class PowerFilter : AuthorizeAtt ...

  7. svm核函数的理解和选择

    https://blog.csdn.net/leonis_v/article/details/50688766 特征空间的隐式映射:核函数    咱们首先给出核函数的来头:在上文中,我们已经了解到了S ...

  8. Mayor's posters---poj2528线段树、离散化

    题目链接:http://poj.org/problem?id=2528 题意:有n张海报要贴,每张需要用的区间为L到R,后面的可以贴在之前的上面,就是吧之前的挡住,求最后我们能看到几张海报: 我们可以 ...

  9. 在django项目中自定义manage命令(转)

    add by zhj 是我增加的注释 原文:http://www.cnblogs.com/holbrook/archive/2012/03/09/2387679.html 我们都用过Django的dj ...

  10. Integer VS AtomicInteger VS MutableInteger

    由于Integer是不可变的,每个循环增加key的value时会创建一个新的对象 每次value+1时不需要重新创建Integer对象 Integer, Boolean 等 is immutable, ...