• 【35.02%】【codeforces 734A】Vladik and flights


    time limit per test2 seconds
    memory limit per test256 megabytes
    inputstandard input
    outputstandard 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 n, a, 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.

    【题目链接】:http://codeforces.com/contest/743/problem/A

    【题解】

    相同的航空公司。直接输出0;
    如果航空公司不一样。
    那么x可以坐x所在的航空公司的飞机到一个和y所在的航空公司临近的位置(免费),然后花费1坐到和y的航空公司一样的机场去。之后到y就免费了.
    所以花费为1;

    【完整代码】

    /*
        a和b的公司一样.
        输出1
        a和b的公司不一样?
        输出1?
        先免费到和b公司的任意一个位置相邻的航班。
        花费1到b公司,
        然后再免费到b
    */
    #include <bits/stdc++.h>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define rei(x) scanf("%d",&x)
    #define rel(x) scanf("%I64d",&x)
    
    typedef pair<int,int> pii;
    typedef pair<LL,LL> pll;
    
    const int MAXN = 1e5+100;
    const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
    const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
    const double pi = acos(-1.0);
    
    char s[MAXN];
    int n,a,b;
    
    int main()
    {
        //freopen("F:\rush.txt","r",stdin);
        rei(n);rei(a);rei(b);
        scanf("%s",s+1);
        if (a==b)
        {
            puts("0");
        }
        else
            if (s[a]==s[b])
                puts("0");
            else
                puts("1");
        return 0;
    }
  • 相关阅读:
    electrica writeup
    C++ Tips and Tricks
    net-force.nl/steganography writeup
    3*n/2
    C++ 关键字浅谈
    MindMaster激活教程
    gitignre
    python pil 安装
    ubuntu 阿里云安全配置
    阿里云 centos 环境配置与 django 部署
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626820.html
Copyright © 2020-2023  润新知