我是靠谱客的博主 冷傲跳跳糖,最近开发中收集的这篇文章主要介绍Codeforces Round #384 (Div. 2) A Vladik and flights,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

A. 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.

题意:有两家公司,分别用0和1代表,飞机从A飞机场到A飞机场不用钱,从A到B要支付距离费用。
分析:所以其实只有两种情况 ·1 不需要转机场直接到达 2转一次机场
所以最多只需要支付1。

#include<stdio.h>
#include<string.h>
char map[200000];
int main()
{
int n,a,b;
scanf("%d%d%d",&n,&a,&b);
scanf("%s",map);
if(map[a-1]==map[b-1])
printf("0n");
else
printf("1n");
}

最后

以上就是冷傲跳跳糖为你收集整理的Codeforces Round #384 (Div. 2) A Vladik and flights的全部内容,希望文章能够帮你解决Codeforces Round #384 (Div. 2) A Vladik and flights所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(47)

评论列表共有 0 条评论

立即
投稿
返回
顶部