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

    A. Vladik and flights

    题目链接

    http://codeforces.com/contest/743/problem/A

    题面

    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.

    输入

    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.

    输出

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

    样例输入

    4 1 4
    1010

    样例输出

    1

    题意

    两个属于相同type的城市的旅游的话,花费为0

    不同的花费为1

    问你从a到b的最小花费是多少

    题解

    显然不是1就是0= =

    代码

    #include<bits/stdc++.h>
    using namespace std;
    
    int n,a,b;
    string s;
    int main()
    {
        scanf("%d%d%d",&n,&a,&b);
        cin>>s;
        if(s[a-1]==s[b-1])cout<<"0"<<endl;
        else cout<<"1"<<endl;
    }
  • 相关阅读:
    比较对象的相对性
    深拷贝与浅拷贝(TBD)
    创建UI的线程才能访问UI,那么怎样才算访问UI呢
    多层级的数据绑定效果
    众所周知,static修饰的成员只实例化一次,而string类型每次赋值都会重新创建一个实例,那么用static修饰string呢?
    常量、只读字段
    使用dos打开相关软件
    查看电脑硬件信息dos命令
    Windows常用快捷键
    使用外部编辑器出现乱码
  • 原文地址:https://www.cnblogs.com/qscqesze/p/6188653.html
Copyright © 2011-2022 走看看