• Codeforces 743A. Vladik and flights


    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.

    仔细阅读后发现其实只有两种可能,机场一样就直接0,机场不一样就是1

    #include <cstdio>
    #include <cctype>
    #include <stdlib.h>
    #include <iostream>
    #include <cmath>
    #include <iomanip>
    #include <cstring>
    #include <algorithm>
    #include <string>
    #include <vector>
    #include <map>
    
    using namespace std;
    typedef long long LL;
    
    char air[100005] = {0};
    int n,a,b;
    int main()
    {
      // freopen("test.in","r",stdin);
      cin >> n >> a >> b;
      for (int i=1;i<=n;i++){
        cin >> air[i];
      }
      if (air[a] == air[b]){
        cout << 0; 
      }
      else
        cout << 1;
    
      return  0;
    }
    View Code
  • 相关阅读:
    IDEA Inspections详解
    IDEA 阿里编码规范插件
    IDEA Save Actions插件
    IDEA Lombok插件
    设计模式-简单工厂模式与工厂模式
    DAO设计模式
    Jcrop+strut2+jsp实现图片剪切
    Spring的Bean的作用域
    Spring的事务机制
    windows 下 Redis 主从 读写分离
  • 原文地址:https://www.cnblogs.com/ToTOrz/p/6856335.html
Copyright © 2020-2023  润新知