• Codeforces Round #180 (Div. 2) AB


    A. Snow Footprints
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i+1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i-1)-th block, he will leave a left footprint on the i-th block. If there already is a footprint on the i-th block, the new footprint will cover the old one.

    Codeforces Round 180 (Div. 2) AB - qhn999 - 码代码的猿猿

    At the beginning, there were no footprints. Then polar bear Alice starts from the s-th block, makes a sequence of moves and ends in thet-th block. It is known that Alice never moves outside of the road.

    You are given the description of Alice's footprints. Your task is to find a pair of possible values of s,t by looking at the footprints.

    Input

    The first line of the input contains integer n (3≤n≤1000).

    The second line contains the description of the road — the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint).

    It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.

    Output

    Print two space-separated integers — the values of s and t. If there are several possible solutions you can print any of them.

    Sample test(s)
    input
    9
    ..RRLL...
    output
    3 4
    input
    11
    .RRRLLLLL..
    output
    7 5
    Note

    The first test sample is the one in the picture.



     
    #include <iostream>


    using namespace std;


    char str[1005];

    int sR=0,sL=0;

    int posR,posL;


    int main()

    {

        int begin,end;

        int n;

        cin>>n;

        for(int i=0;i<n;i++)

        {

            cin>>str;

            if(str=='R')

            {

                if(sR==0)

                    posR=i;

                sR=1;

            }

            if(str=='L')

            {

                if(sL==0)

                    posL=i;

                sL=1;

            }

        }


        if(sR&&sL)

            {

                begin=posR+1;

                end=posL;

            }


        else if(sR==1&&sL==0)

        {

            begin=posR+1;

            for(int i=posR;i<n;i++)

            {

                if(str=='.')

                {

                    end=i+1;

                    break;

                }

            }

        }

        else if(sL==1&&sR==0)

        {

            end=posL;

            for(int i=posL;i<n;i++)

            {

                if(str=='.')

                {

                    begin=i;

                    break;

                }

            }

        }


        cout<<begin<<" "<<end<<endl;


        return 0;

    }


    B. Sail
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    The polar bears are going fishing. They plan to sail from (sx,sy) to (ex,ey). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (x,y).

    • If the wind blows to the east, the boat will move to (x+1,y).
    • If the wind blows to the south, the boat will move to (x,y-1).
    • If the wind blows to the west, the boat will move to (x-1,y).
    • If the wind blows to the north, the boat will move to (x,y+1).

    Alternatively, they can hold the boat by the anchor. In this case, the boat stays at (x,y). Given the wind direction for t seconds, what is the earliest time they sail to (ex,ey)?

    Input

    The first line contains five integers t,sx,sy,ex,ey (1≤t≤105,-109sx,sy,ex,ey≤109). The starting location and the ending location will be different.

    The second line contains t characters, the i-th character is the wind blowing direction at the i-th second. It will be one of the four possibilities: "E" (east), "S" (south), "W" (west) and "N" (north).

    Output

    If they can reach (ex,ey) within t seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes).

    Sample test(s)
    input
    5 0 0 1 1
    SESNW
    output
    4
    input
    10 5 3 3 6
    NENSWESNEE
    output
    -1
    Note

    In the first sample, they can stay at seconds 13, and move at seconds 24.

    In the second sample, they cannot sail to the destination.

     



    #include <iostream>
    #include <cmath>

    using namespace std;

    int main()
    {
        char tx='X',ty='X';
        char c;
        int t,sx,sy,ex,ey;
        cin>>t>>sx>>sy>>ex>>ey;

        int dx=ex-sx;
        int dy=ey-sy;

        if(dx>0)
        {
            tx='E';
        }
        else if(dx<0)
        {
            tx='W';
        }

        if(dy>0)
        {
            ty='N';
        }
        else if(dy<0)
        {
            ty='S';
        }

        int nx=abs(dx),ny=abs(dy);
        int ans=-2;
     //   cout<<tx<<" "<<ty<<endl;
        for(int i=0;i<t;i++)
        {
            cin>>c;
     //       cout<<c<<" i: "<<i<<" "<<nx<<" "<<ny<<endl;

                if(c==tx&&nx!=0)
                {
                    nx--;
                }
                if(c==ty&&ny!=0)
                 {
                    ny--;
                 }

            if(nx==0&&ny==0)
            {
                ans=i;
                break;
            }
        }

        cout<<ans+1<<endl;
        return 0;
    }



     
  • 相关阅读:
    一个强迫症用户的锤子手机使用体验
    起点——2015年终总结
    用“MEAN”技术栈开发web应用(三)用mongodb搭建数据库
    用“MEAN”技术栈开发web应用(二)express搭建服务端框架
    SpringBoot/Spring使用@Value进行属性绑定(尚硅谷)
    springboot/spring使用ConfigurationProperties注解读取自定义属性(尚硅谷)
    Spring Boot项目中@SpringBootTest测试的时候卡住,一直Resolving Maven dependencies...
    ASP.NET项目:请使用语言版本6或者更高版本
    安装CUDA坑:CUDA driver version is insufficient for CUDA runtime version
    Failed to load the native TensorFlow runtime. ImportError: libcuda.so.1: cannot open shared object file: No such file or directory
  • 原文地址:https://www.cnblogs.com/CKboss/p/3351092.html
Copyright © 2020-2023  润新知