zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    20200209 ZooKeeper 3. Zookeeper内部原理
    20200209 ZooKeeper 2. Zookeeper本地模式安装
    20200209 Zookeeper 1. Zookeeper入门
    20200206 尚硅谷Docker【归档】
    20200206 Docker 8. 本地镜像发布到阿里云
    20200206 Docker 7. Docker常用安装
    20200206 Docker 6. DockerFile解析
    20200206 Docker 5. Docker容器数据卷
    20200206 Docker 4. Docker 镜像
    Combining STDP and Reward-Modulated STDP in Deep Convolutional Spiking Neural Networks for Digit Recognition
  • 原文地址:https://www.cnblogs.com/nextbin/p/3704508.html
Copyright © 2011-2022 走看看