Maximum Sequence

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1450    Accepted Submission(s): 673

Sample Input
4
8 11 8 5
3 1 4 2
Sample Output
27

Hint

For the first sample:
1. Choose 2 from {bi}, then a_2…a_4 are available for a_5, and you can let a_5=a_2-2=9;
2. Choose 1 from {bi}, then a_1…a_5 are available for a_6, and you can let a_6=a_2-2=9;

Source
题意:给你一个a数组  代表这个数组里的数值  给你一个b数组  代表a数组的位序  在b数组中选一个值  进行奇葩(解释不清楚)操作
8 11 8 5
3 1 4 2  选2   a变成-》8 11 8 5 9  在选1-》 8 11 8 5 9 9  再选3变成8 11 8 5 9 9 5  在选4-》8 11 8 5 9 9 5 4
求增加的数字和最大为多少
题解:其实将b数组排个序 从小到大选取 用一个优先队列维护一下是不是可以取到最大值  因为b数组的值不确定
 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<string.h>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<cmath>
typedef long long ll;
typedef unsigned long long LL;
using namespace std;
const double PI=acos(-1.0);
const double eps=0.0000000001;
const int N=+;
const ll mod=1e9+;
int a[N],b[N];
struct node{
int num;
int pos;
friend bool operator<(node aa,node bb){
return aa.num<bb.num;
}
};
priority_queue<node>q;
int main(){
int n;
while(scanf("%d",&n)!=EOF){
// memset(c,0,sizeof(c));
while(!q.empty())q.pop();
node c;
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
c.num=a[i]-i;
c.pos=i;
q.push(c);
}
//cout<<q.top().num<<endl;
for(int i=;i<=n;i++)scanf("%d",&b[i]);
sort(b+,b++n);
ll ans=;
node t;
int tt=n+;
for(int i=;i<=n;i++){
while(b[i]>q.top().pos)q.pop();
if(q.empty()==)break;
c=q.top();
ans=(ans+c.num)%mod;
t.num=c.num-tt;
t.pos=tt;
q.push(t);
tt++;
//cout<<c.num<<endl;
}
ans%=mod;
printf("%I64d\n",ans);
}
}

2017 Multi-University Training Contest - Team 2&&hdu 6047 Maximum Sequence的更多相关文章

  1. HDU 6047 - Maximum Sequence | 2017 Multi-University Training Contest 2

    /* HDU 6047 - Maximum Sequence [ 单调队列 ] 题意: 起初给出n个元素的数列 A[N], B[N] 对于 A[]的第N+K个元素,从B[N]中找出一个元素B[i],在 ...

  2. 2017 Multi-University Training Contest - Team 2 &&hdu 6050 Funny Function

    Funny Function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  3. 2017 Multi-University Training Contest - Team 2 &&hdu 6053 TrickGCD

    TrickGCD Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  4. HDU 6047 Maximum Sequence

    Maximum Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. HDU 6047 Maximum Sequence(线段树)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=6047 题目: Maximum Sequence Time Limit: 4000/2000 MS (J ...

  6. HDU 6047 Maximum Sequence(贪心+线段树)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=6047 题目: Maximum Sequence Time Limit: 4000/2000 MS (J ...

  7. 2017 Multi-University Training Contest - Team 2 &hdu 6055 Regular polygon

    Regular polygon Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  8. 【2017 Multi-University Training Contest - Team 7 && hdu 6121】Build a tree

    [链接]点击打开链接 [题意] 询问n个点的完全k叉树,所有子树节点个数的异或总和为多少. [题解] 考虑如下的一棵k=3叉树,假设这棵树恰好有n个节点. 因为满的k叉树,第i层的节点个数为k^(i- ...

  9. 【 2017 Multi-University Training Contest - Team 9 && hdu 6162】Ch’s gift

    [链接]h在这里写链接 [题意] 给你一棵树,每个节点上都有一个权值. 然后给你m个询问,每个询问(x,y,a,b); 表示询问x->y这条路径上权值在[a,b]范围内的节点的权值和. [题解] ...

随机推荐

  1. hdu3535题解

    hdu3535:http://acm.hdu.edu.cn/showproblem.php?pid=3535 该题是非常全面的一道分组背包问题.其实理解了最多一个的分组背包问题,解题起来也是很简单的. ...

  2. T-SQL语句以及几个数据库引擎

    创建表 注意事项: A.自增长             B.数据库引擎, ISAM 是一个定义明确且历经时间考验的数据表格管理方法,它在设计之时就考虑到数据库被查询的次数要远大于更新的次数.因此,IS ...

  3. async await 同步方法调用异步方法死锁

    同步方法调用异步方法.GetAwaiter().GetResult()计算函数超时,异步方法所有的回调操作都会期望返回到主线程. 所以会导致各种线程死锁.异步方法中使用ConfigureAwait(f ...

  4. 关于Python中的classmethod

    Python 中的 classmethod classmethod: 作用是直接将自己的类对象,传给类方法. 一.classmethod 1)不用classmethod的时候 你的代码可能是这样写的, ...

  5. C# 把时间 月 //把第一个0替换为空

    string str = "2019-01"; //name: "2019-01月" str = str.Substring(str.Length - , ); ...

  6. PHP 之文件锁解决并发问题

    一.参数说明 $handle: 文件资源 $operation: 锁的类型 LOCK_SH: 共享锁 LOCK_EX: 排他锁 LOCK_UN: 释放锁 $wouldblock: 设置为true的时候 ...

  7. centos添加永久的环境变量

    cd /etc/profile.d/ 创建一个sh文件 vi dotnetpath.sh 内容如下: export PATH=$PATH:/opt/dotnet 保存,重启,这就有了一个永久的环境变量

  8. u-boot常用命令

    查看ip地址等信息 print tftp相关 设置ip地址 set ipaddr 192.168.1.5 设置tftp所在电脑ip set serverip 192.168.1.8 最后必须输入sav ...

  9. $.extend 合并对象(处理可传入0个或多个参数)

    function test(options){             $.extend({ },this.Default,options);                  var v = thi ...

  10. java同学毕业后学习之路建议

    第一部分:对于尚未做过Java工作的同学,包括一些在校生以及刚准备转行Java的同学. 滤过: 第二部分:对于参加工作一年以内的同学. 恭喜你,这个时候,你已经拥有了一份Java的工作.这个阶段是你成 ...