• UVALive 4953 Wormly--【提醒自己看题要仔细】


    有一条虫要过桥,桥有断的木板和好的木板。虫有L条腿B个身体,桥长N。01串表示桥的好坏。输出最少操作次数。

    一开始虫的身体在最左B桥上,腿在最左L桥上,最后要到达最右B以及最右L。。。

    操作有2种:①所有身体前进一步②某一条腿前进任意步。。。。整个过程要保证每个身体下只能有一条腿。。。。还有就是任意一条腿不能overtake(追上、赶上)其他腿。。

    输入保证起点终点的桥都是完好的。。。

    鉴于中文水平跟英语水平都不高。。。题意请自行YY脑补。。。

    看题不仔细。。。。再次坑队友。。。。大家好,我是坑神=。=真感谢 前度和现队友 对我的体谅。。。。。

    一开始没留意到overtake是这个意思(英语渣),然后上线段树、优先队列。。。。复杂度其实也很高。。。

    赛后看清题意后。。在自己的基础上,加了个sum数组,参考队花NX的。。。。sum[i]表示前i个桥好桥的个数。。。不知为啥比队花的要快。。。看不懂队花的做法。。

    这个复杂度大概是O(n)吧。。。

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 #include <algorithm>
     5 #include <cmath>
     6 #include <string>
     7 #include <vector>
     8 using namespace std;
     9 
    10 #define ll long long
    11 #define mod 1000000007
    12 #define inf 0x3f3f3f3f
    13 #define eps 1e-8
    14 #define maxn 1000010
    15 
    16 char str[maxn];
    17 int sum[maxn];
    18 int main(){
    19     int t;
    20     int leg,body,n;
    21     scanf("%d",&t);
    22     while(t--){
    23         scanf("%d%d%d",&leg,&body,&n);
    24         scanf("%s",str+1);
    25         if(leg==body){
    26             printf("%s
    ",body==n?"0":"IMPOSSIBLE");
    27             continue;
    28         }
    29         sum[0]=0;
    30         for(int i=1;i<=n;++i)sum[i]=sum[i-1]+(str[i]-'0');
    31         bool can=true;
    32         for(int i=body;i<=n;++i)if(sum[i]-sum[i-body]<leg){can=false;break;}
    33         if(can==false){puts("IMPOSSIBLE");continue;}
    34         ll ans=0;
    35         int l=1;
    36         int bb=1,bb2=body;
    37         while(l!=n+1-leg){
    38             if(bb<l&&bb2!=n){
    39                 int dx = min(l-bb,n-bb2);// bb2+dx<=n
    40                 ans+=dx,bb+=dx,bb2+=dx;
    41             }
    42             if(sum[bb2]-sum[l]<leg){can=false;break;}
    43             while(sum[bb2]-sum[l]>=leg)++l;
    44             ans+=leg;
    45         }
    46         if(can)printf("%lld
    ",ans);
    47         else puts("IMPOSSIBLE");
    48     }
    49     return 0;
    50 }
    View Code
  • 相关阅读:
    html,web页面组成 --L简
    python,appium,初步 --L简
    UIautomatorviewer,Error while obtaining UI hierarchy XML file: com.android.ddmlib.SyncException: Remote object doesn't exist!
    python,selenium,初步--L简
    python,入门 --L简
    python,os模块 --L简
    RobotFramework(4)接口自动化 --L简
    RobotFramework(3)web自动化 --L简
    RobotFramework(2)自定义关键字,定义,使用 --L简
    RobotFramework(1),初探 --L简
  • 原文地址:https://www.cnblogs.com/nextbin/p/3704508.html
Copyright © 2020-2023  润新知