Codeforces Round #318 D. Bear and Blocks

Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built n towers in a row. The i-th tower is made of hi identical blocks. For clarification see picture for the first sample.

Limak will repeat the following operation till everything is destroyed.

Block is called internal if it has all four neighbors, i.e. it has each side (top, left, down and right) adjacent to other block or to the floor. Otherwise, block is boundary. In one operation Limak destroys all boundary blocks. His paws are very fast and he destroys all those blocks at the same time.

Limak is ready to start. You task is to count how many operations will it take him to destroy all towers.

这个题目里面,窝们的主角还童啦。。。。。。。

蓝后就要开始做了。 一看到这题目 ,就感觉是要dp。蓝后就是要早状态方程了。

有题意可以知道, 这个题目里面,对第i列进行第1次操作以后, 第i列就剩下 min(h(i-1), hi - 1, h(i+1));

如果进行第二次操作, 就剩下 min(left, hi - 2, right)

left = min(h(i - 2), h(i-1) - 1, hi) right = min(hi , h(i + 1) - 1, h(i+2));  蓝后,如过直接这样推 , 就不知道怎么搞了。

蓝后窝们看一下, 如果不考虑右边 , 就是说对任意一列, 右边总是可行的。

蓝后首先第一列总是一次就能全部消去,所以 l[1] = 1;

蓝后对于第二列 l[2] = min(l[1]+1,t[2]);    如果第二列比第一列高, 那么第一列全部消去以后,第二列还有剩余,蓝而再消去一次,第二列就没啦。

如果第二列比起第一列低, 那么每次消去,第二列都会消去最顶上一个, 总共消去t[2] 次;

然后如果只考虑右边也是一样的。  所以每一列消去要的次数就是min( l[i],r[i]);

最后取个大值就好了

然后官方给的代码还是没理解啊

#include 
   
   
    
    
#include 
    
    
     
     
#include 
     
     
      
      
using namespace std;
int dp[200000];
int t[200000];
int l[200000];
int r[200000];
int n;
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        for(int i = 1; i <= n; i++)
        {
            scanf("%d",&t[i]);
        }
        l[1] = 1;
        for(int i = 2; i <= n; i++)
        {
            l[i] = min(l[i-1] + 1, t[i]);
        }
        r[n] = 1;
        for(int i = n-1; i >= 1; i--)
        {
            r[i] = min(r[i+1] + 1, t[i]);
        }
        int ans = 0;
        for(int i = 1; i <= n; i++)
        {
            ans = max(ans,min(l[i],r[i]));
        }
        printf("%d\n",ans);
    }
    return 0;
}

     
     
    
    
   
   
#include<bits/stdc++.h>
using namespace std;
const int nax = 1e6 + 5;
const int inf = 1e9 + 5;

int t[nax], res[nax];

int main() {
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) scanf("%d", &t[i]);
	int worst = 0;
	for(int i = 1; i <= n; ++i) {
		worst = min(worst, t[i]-i);
		res[i] = i + worst;
	}
	worst = n + 1;
	for(int i = n; i >= 1; --i) {
		worst = min(worst, t[i]+i);
		res[i] = min(res[i], worst-i);
	}
	int R = 0;
	for(int i = 1; i <= n; ++i)
		R = max(R, res[i]);
	printf("%d\n", R);
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值