E-Game_2020牛客暑期多校训练 第十场 E 前缀和

题目:
There are n columns of blocks standing in a row. The i-th column has ai blocks in the beginning. Each block has size 1\times 1\times 11×1×1. Define (x,y) represent the block at column x and is the y-th block from bottom to top. You can perform one operation:

  • Push one block to the left, that means you choose one block which has no block at its right and make it move to the left. Because of the friction, the block above it will also move to the left, and because the blocks cannot intersect, the block at its left will move to the left either. This will cause a chain reaction. After every block moved, if some blocks hang in the air, then it will fall because of gravitation. Note that the blocks at column 1 can’t move to the left, so if a movement will cause a block at column 1 move, you can’t perform this operation.then you can perform this operation as long as l exists. Then for all blocks (i,j) that satisfy l< i\leq xl<i≤x and j\geq yj≥y, it moves to (i-1,j). After that, for blocks (x,y) (y>1) that there are no blocks in (x,y-1), it moves to (x,y-1). Repeat doing it until no blocks satisfy the condition.
  • 起初
    2
    3
    输入输出:
    在这里插入图片描述
    题意:推箱子,只能往左推,不能推最下面那一层,推完后会产生链式反应左边的都被推,考虑重力下降。
    思路:
    箱子排布麻烦的只可能是左高右低,中间高和右边高直接往左推就完事了,也就是直接一平均,如果能整除分配到每一列,那就整除,如果不行,就+1处理,如果是左边高会麻烦,因为左边不能往右边推,所以我们从左开始判断,用前缀和从左遍历一次加一列,用ans更新最高。
    #include
    #include
    #include
    using namespace std;
    typedef long long ll;
    const int N = 1e5 + 10;
    ll s[N],a[N];
    int n;
    int main()
    {
    int T;
    scanf("%d", &T);
    while (T–)
    {
    cin >> n;
    for (int i = 1; i <= n; i++)cin >> a[i], s[i] = s[i - 1] + a[i];
    ll ans=0;
    for (int i = 1; i <= n; i++)
    { if(s[i]%i==0)ans=max(ans,s[i]/i);
    else ans=max(ans,s[i]/i+1);
    }
    cout << ans << endl;
    }
    return 0;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值