zoukankan      html  css  js  c++  java
  • Codeforces Round #384 (Div. 2) A. Vladik and flights

    A. Vladik and flights
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.

    Vladik knows n airports. All the airports are located on a straight line. Each airport has unique id from 1 to n, Vladik's house is situated next to the airport with id a, and the place of the olympiad is situated next to the airport with id b. It is possible that Vladik's house and the place of the olympiad are located near the same airport.

    To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport a and finish it at the airport b.

    Each airport belongs to one of two companies. The cost of flight from the airport i to the airport j is zero if both airports belong to the same company, and |i - j| if they belong to different companies.

    Print the minimum cost Vladik has to pay to get to the olympiad.

    Input

    The first line contains three integers na, and b (1 ≤ n ≤ 105, 1 ≤ a, b ≤ n) — the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.

    The second line contains a string with length n, which consists only of characters 0 and 1. If the i-th character in this string is 0, then i-th airport belongs to first company, otherwise it belongs to the second.

    Output

    Print single integer — the minimum cost Vladik has to pay to get to the olympiad.

    Examples
    input
    4 1 4
    1010
    output
    1
    input
    5 5 2
    10110
    output
    0
    Note

    In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1.

    In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.

    就这么简单,答案不是1就是0

     1 #include <iostream>
     2 #include <string>
     3 #include <algorithm>
     4 using namespace std;
     5 
     6 int main(){
     7     string str;
     8     int n,a,b;
     9     cin>>n>>a>>b;
    10     cin>>str;
    11     if(str[a-1]==str[b-1])
    12         cout<<0<<endl;
    13     else
    14         cout<<1<<endl;
    15     return 0;
    16 }
    自己选的路,跪着也要把它走完------ACM坑
  • 相关阅读:
    Android系统源代码下载
    Windows Embedded Compact 7初体验
    windowsmobile 开发环境
    Windows X64汇编入门(1)
    汇编语言的Hello World
    如何构建Win32汇编的编程环境(ONEPROBLEM个人推荐)
    音频视频解决方案:GStreamer/ffmpeg/ffdshow/directshow/vfw
    汇编开发环境
    DirectX
    关于DirectShow SDK 和Windows SDK,及DirectX SDK
  • 原文地址:https://www.cnblogs.com/IKnowYou0/p/6182723.html
Copyright © 2011-2022 走看看