HDU 6047 贪心思维题
Maximum Sequence
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1797 Accepted Submission(s): 842
Given two integer sequences {ai} and {bi} with the same length n, you are to find the next n numbers of {ai}: an+1…a2n
. Just like always, there are some restrictions on an+1…a2n
: for each number ai
, you must choose a number bk
from {bi}, and it must satisfy ai
≤max{aj
-j│bk
≤j<i}, and any bk
can’t be chosen more than once. Apparently, there are a great many possibilities, so you are required to find max{∑2nn+1ai
} modulo 109
+7 .
Now Steph finds it too hard to solve the problem, please help him.
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.
} modulo 109
+7。
分析可知 ,a_n+1-------a_2*n必定是一个非严格递减序列,由此可知对a_n+1-a_2*n有贡献的只可能是a_1-a_n+1(因为a_n+1-a_2*n是一个非严格递减序列)
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
const int mod=1e9+;
int a[N],b[N],Max[N];
int main(){
int n;
while(scanf("%d",&n)!=EOF){
for(int i=;i<=n;++i) scanf("%d",&a[i]),a[i]-=i;
for(int i=;i<=n;++i) scanf("%d",&b[i]);
Max[n]=a[n];
for(int i=n-;i>=;--i) Max[i]=max(Max[i+],a[i]);
sort(b+,b+n+);
int ans1=Max[b[]]-n-,ans=Max[b[]];
for(int i=;i<=n;++i) ans=(ans+max(Max[b[i]],ans1))%mod;
printf("%d\n",ans);
}
}
HDU 6047 贪心思维题的更多相关文章
- hdu 4803 贪心/思维题
http://acm.hdu.edu.cn/showproblem.php?pid=4803 话说C++还卡精度么? G++ AC C++ WA 我自己的贪心策略错了 -- 就是尽量下键,然后上 ...
- 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas
题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...
- 贪心/思维题 UVA 11292 The Dragon of Loowater
题目传送门 /* 题意:n个头,m个士兵,问能否砍掉n个头 贪心/思维题:两个数组升序排序,用最弱的士兵砍掉当前的头 */ #include <cstdio> #include <c ...
- ZOJ 3829 贪心 思维题
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ...
- hdu 4091 数学思维题贪心
/* 参看博客地址:http://blog.csdn.net/oceanlight/article/details/7857713 重点是取完最优的后剩余的rest=n%lcm+lcm;中性价比小的数 ...
- 【贪心 思维题】[USACO13MAR]扑克牌型Poker Hands
看似区间数据结构的一道题 题目描述 Bessie and her friends are playing a unique version of poker involving a deck with ...
- HDU 5776 sum (思维题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5776 题目让你求是否有区间的和是m的倍数. 预处理前缀和,一旦有两个数模m的值相同,说明中间一部分连续 ...
- hdu 1009 贪心基础题
B - 贪心 基础 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:32768KB 64bi ...
- PAT 甲级 1067 Sort with Swap(0, i) (25 分)(贪心,思维题)*
1067 Sort with Swap(0, i) (25 分) Given any permutation of the numbers {0, 1, 2,..., N−1}, it is ea ...
随机推荐
- hdu_2391 Filthy Rich DP
Filthy Rich Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- axios的使用小技巧:如何绕过字符串拼接,直接传递对象
Vue.js官方推荐使用axios作为发送http请求的工具,在使用axios中,有些小技巧是不容易发现的.当我们不知道这些技巧时,我们可能会使用其他"奇技淫巧",比如,我们很容 ...
- JavaScript Array every()&some()&reduce()方法
every()方法测试数组的所有元素是否都通过了指定函数的测试. // 每一项都要满足条件才会返回true,只要有一项不满足返回false var arr = [1, 2, 3, 4]; let bl ...
- 搭建Springboot+mybatis+redis+druid
2019独角兽企业重金招聘Python工程师标准>>> 准备工作 JDK:1.8 使用技术:SpringBoot.Dubbo.Mybatis.Druid 开发工具:Intelj ID ...
- js中的filter
filter是常说的增删改查中的'查',当对一个数组进行筛选时,经常会使用indexOf 和es6中的includes()方法.filter是es5中的一种迭代方法,其定义为:对数组中的每一项运行给定 ...
- #if 和#ifdef的区别
转自:https://blog.csdn.net/zhangchiytu/article/details/7563329 先看个例子:#define TARGET_LITTLE_ENDINA 1#de ...
- VScode像Codeblocks一样,不启动调试和Debug直接运行
要是配置C++ 编译环境,这边走 用了VScode童鞋,都知道,写C++是不保留窗口的,除非打上断点或者: system("pause"); 这里给大家分享一种不需要,F5或者Ct ...
- ACM成长之路(干货) 我爱ACM,与君共勉
前几天在网上看到,转过来时刻督促一下自己. ACM队不是为了一场比赛而存在的,为的是队员的整体提高. 大学期间,ACM队队员必须要学好的课程有: l C/C++两种语言 l 高等数学 l 线性代数 l ...
- 图论--SCC强连通缩点--Tarjan
强连通缩点与双连通缩点大同小异,也就是说将强连通分支缩成一个点之后,没有强连通,成为有向无环图,在对图进行题目的操作. // Tarjan算法求有向图强连通分量并缩点 #include<iost ...
- DataHub——实时数据治理平台
DataHub 首先,阿里云也有一款名为DataHub的产品,是一个流式处理平台,本文所述DataHub与其无关. 数据治理是大佬们最近谈的一个火热的话题.不管国家层面,还是企业层面现在对这个问题是越 ...