2017 多校训练第二场 HDU 6047 Maximum Sequence(贪心+优先队列)
来源:互联网 发布:萧敬腾唱功知乎 编辑:程序博客网 时间:2024/05/18 12:42
Maximum Sequence
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2404 Accepted Submission(s): 1131
Problem Description
Steph is extremely obsessed with “sequence problems” that are usually seen on magazines: Given the sequence 11, 23, 30, 35, what is the next number? Steph always finds them too easy for such a genius like himself until one day Klay comes up with a problem and ask him about it.
Given two integer sequences {ai} and {bi} with the same length n, you are to find the next n numbers of {ai}: $a_{n+1}…a_{2n}$. Just like always, there are some restrictions on $a_{n+1}…a_{2n}$: for each number $a_i$, you must choose a number $b_k$ from {bi}, and it must satisfy $a_i$≤max{$a_j$-j│$b_k$≤j<i}, and any $b_k$ can’t be chosen more than once. Apparently, there are a great many possibilities, so you are required to find max{$\sum_{n+1}^{2n}a_i$} modulo $10^9$+7 .
Now Steph finds it too hard to solve the problem, please help him.
Given two integer sequences {ai} and {bi} with the same length n, you are to find the next n numbers of {ai}: $a_{n+1}…a_{2n}$. Just like always, there are some restrictions on $a_{n+1}…a_{2n}$: for each number $a_i$, you must choose a number $b_k$ from {bi}, and it must satisfy $a_i$≤max{$a_j$-j│$b_k$≤j<i}, and any $b_k$ can’t be chosen more than once. Apparently, there are a great many possibilities, so you are required to find max{$\sum_{n+1}^{2n}a_i$} modulo $10^9$+7 .
Now Steph finds it too hard to solve the problem, please help him.
Input
The input contains no more than 20 test cases.
For each test case, the first line consists of one integer n. The next line consists of n integers representing {ai}. And the third line consists of n integers representing {bi}.
1≤n≤250000, n≤a_i≤1500000, 1≤b_i≤n.
For each test case, the first line consists of one integer n. The next line consists of n integers representing {ai}. And the third line consists of n integers representing {bi}.
1≤n≤250000, n≤a_i≤1500000, 1≤b_i≤n.
Output
For each test case, print the answer on one line: max{$\sum_{n+1}^{2n}a_i$} modulo $10^9$+7。
Sample Input
48 11 8 53 1 4 2
Sample Output
27HintFor 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
2017 Multi-University Training Contest - Team 2
题意:构造an+1到a2*n的数。构造方法是从bi中选一个数使得ai≤max{aj-j│bk≤j<i}。bi只能被选一次。求构造出来的an+1到a2*n的最大值。
思路:
aj-j中的aj是从原来a1到an中来的,而j的值是一直变大的。所以应该把大的值先加入ai+n中。
所以可以先将bi从小到大排序。用一个优先队列,存放ai-i的值,以它的较大值为优先级较高的。在构造出一个ai+n的时候并把ai+n-(i+n)放入队列中。继续往后构造,这样就能使得和最大。
#include <iostream>#include <cstdio>#include <cstring>#include <queue>#include <algorithm>using namespace std;const int maxn=500010;const int mod=1e9+7;struct node{ int i,w; friend bool operator<(node a,node b) { return a.w<b.w; }}q[maxn];int b[maxn];int main(){ int n; while(~scanf("%d",&n)) { priority_queue<node> que; for(int i=1;i<=n;i++) { scanf("%d",&q[i].w); q[i].w=q[i].w-i; q[i].i=i; que.push(q[i]); } for(int i=1;i<=n;i++) scanf("%d",&b[i]); sort(b+1,b+1+n); long long sum=0; for(int i=1;i<=n;i++) { while(que.top().i<b[i]) que.pop(); node tmp=que.top(); sum=(sum+tmp.w)%mod; tmp.i=i+n,tmp.w=tmp.w-tmp.i; que.push(tmp); } printf("%lld\n",sum); } return 0;}
阅读全文
0 0
- 2017 多校训练第二场 HDU 6047 Maximum Sequence(贪心+优先队列)
- 2017 多校训练第二场 HDU 6047 Maximum Sequence
- 2017多校训练第二场 hdu6047 Maximum Sequence(贪心)
- (2017多校训练第二场)HDU
- (2017多校训练第二场)HDU
- (2017多校训练第二场)HDU
- (2017多校训练第二场)HDU
- (2017多校训练第二场)HDU
- Hdu 6047 Maximum Sequence【贪心+优先队列】
- HDU 6047 (2017 多校训练赛2 1003)Maximum Sequence
- HDU-2017 多校训练赛2-1003-Maximum Sequence
- 2017 多校训练第二场 HDU 6055 Regular polygon
- 2017 多校训练第二场 HDU 6050 Funny Function
- 2017 多校训练第二场 HDU 6053 TrickGCD
- 2017 杭电多校联赛第二场 1003 Maximum Sequence(单调队列)HDU 6047
- 2017多校训练赛第四场 HDU 6078 Wavel Sequence(dp+优化)
- 2017多校训练赛第二场 HDU 6052(统计+思维)
- 2017多校训练赛第二场 HDU 6051 (数论)——By alpc_wh
- 计算机视觉大规模爆发,6大细分领域将撑起725亿元市场
- 大学生活随笔
- margin外边距折叠
- 关于安装redis服务java客户端提示超时
- 15. 集合类(Collection、List)
- 2017 多校训练第二场 HDU 6047 Maximum Sequence(贪心+优先队列)
- alert中的换行及常用转义字符
- Raspberry Pi GPU Audio Video Programming.pdf 英文原版 免费下载
- 配置vim,以及linux下的编辑器和编译器
- 一个简单的检查版本更新
- 安装第三方库
- 随机获取时间
- caffe模型融合
- Java的四种引用方式