zoukankan      html  css  js  c++  java
  • 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

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

  • 相关阅读:
    [CF-Edu113]D. Inconvenient Pairs
    第3组团队Git现场编程实战
    团队项目-选题报告
    第一次个人编程作业
    第一次软工博客作业
    (二十二)python 3 sort()与sorted()
    (二十一)python 3 内置函数
    (二十)python 3 匿名函数
    (十九)python 3 内嵌函数和闭包
    (十八)python 3 回调函数
  • 原文地址:https://www.cnblogs.com/FriskyPuppy/p/7248290.html
Copyright © 2011-2022 走看看