HDU 6047 Maximum Sequence 思维

  题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6047

  题目描述: 有数组a, b长度都为n ......解释起来好麻烦, 自己看题吧

  解题思路: 由性质可知添加的n个数一定是单调递减的, 所以我们可知最后的n个数一定是取了前 n+1的数中的某些数, 如果一个数大于下标其下标大的, 则更新

  代码: (徐文栋的, 很巧

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
const int maxn = 250500;
const LL mod = (LL)1e9+7;
int n;
LL a[maxn], b[maxn];

signed main() {
    // freopen("in", "r", stdin);
    while(~scanf("%d", &n)) {
        a[n+1] = 0;
        for(int i = 1; i <= n; i++) scanf("%lld", &a[i]);
        for(int i = 1; i <= n; i++) scanf("%lld", &b[i]);
        for(int i = n; i >= 1; i--) {
            a[i] -= i;
            a[i] = max(a[i], a[i+1]);
        }
        sort(b+1, b+n+1);
        LL ret = 0, flag = 0;
        for(int i = 1; i <= n; i++) {
            LL x = max(flag, a[b[i]]);
            ret = (ret + x) % mod;
            flag = max(flag, x-(n+i));
        }
        printf("%lld\n", ret);
    }
    return 0;
}
View Code

  思考: 这是我写的最差的一篇博客了......虽然其他的也不好, 这题我能够想出来但是还是实现不出来.....玛丽啊!

posted on 2017-07-28 08:51  FriskyPuppy  阅读(135)  评论(0编辑  收藏  举报

导航