Problem B. Mural Google Kickstart Round H 2018

题意:画家在墙上画壁画,墙在水平方向被分成N段,每一段有一个value值。画家每天画一段而且只能在已经画过的sections边上接着画。每天会来一次洪水,洪水会毁掉未被画过的,且之和一个section相连的部分。被洪水会掉的部分不能在画画。问在worst case下,画家能得到的最大value是多少。

这一题题目很绕,洪水每次只能毁掉剩余的section中最左边or最右边没被画过的部分。画家画的壁画也是连续的。看到worst case还以为是博弈,但是博弈我只会dp,但博弈dp里面先手后手的行为要是相同的。然而开始没看懂题目要求worst case,发现test case里面的结果是长度为N/2 or N/2+1的子序列最大和。

后来想想,因为画家的action更加active,所以可以保证其画到的是和最大的子序列。如果flood已经到达了max susequence边上,画家可以先将那个边界画上。

比如: 1 0 2 9 3 8 4 7 5 6,最大子序列是 9 3 8 4 7

最佳策略是从8开始画。如果洪水的顺序是先左边后右边,策略是:paint 8, destroy 1, parint 3, destroy 0, paint 9 destroy 2, paint 4 destroy 6, paint 7, destroy 5

如果洪水的顺序是左右交替,策略是:paint 8, destroy 1, parint 4, destroy 6, paint 3 destroy 0, paint 7 destroy 5, paint 9, destroy 2

如果洪水的顺序是右左交替,策略是:paint 8, destroy 6, parint 4, destroy 1, paint 3 destroy 5, paint 7 destroy 0, paint 9, destroy 2

感觉最佳策略是从中心开始画,因为这样可以向左向右都expand。如果洪水毁了左边,在center的左边画一个section,如果洪水毁了右边,就在center右边画一个section。

#include<iostream>
#include<stdio.h>
#include<cstdio>
#include<string>
#include<cmath>
#include<stdlib.h>
#include<algorithm>
#include<string.h>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;

//Kickstart Round H Problem B

const int maxn=5*1e6+10;
int T;
int N;
int arr[maxn];
int ans;
int main()
{
    int x=maxn*9;
    cout<<x<<endl;
    return 0;
//    freopen("input.txt","r",stdin);
    freopen("B-large.in","r",stdin);
    freopen("B-large.txt","w",stdout);
    clock_t START_TIME;
    clock_t FINISH_TIME;
    START_TIME=clock();
    scanf("%d",&T);

    for(int ca=1;ca<=T;ca++)
    {
        memset(arr,0,sizeof(arr));
        ans=0;
        cin>>N;
        string tmp;
        cin>>tmp;
        cin.ignore();
        for(int i=0;i<N;i++)
        {
            arr[i]=tmp[i]-'0';
        }
        int len=0;
        if(N%2==0)
        {
            len=N/2;
        }
        else
        {
            len=N/2+1;
        }
        int windowsum=0;
        for(int i=0;i<len-1;i++)
        {
            windowsum+=arr[i];
        }
        for(int i=0;i+len<=N;i++)
        {
            windowsum+=arr[i+len-1];
            ans=max(ans,windowsum);
            windowsum-=arr[i];
        }
        printf("Case #%d: %d\n",ca,ans);
        cerr<<"finish case "<<ca<<endl;

    }

    FINISH_TIME=clock();
    cerr<<1.0*(FINISH_TIME-START_TIME)/CLOCKS_PER_SEC <<" (s) "<<endl;
    return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值