codeforce.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 ≤ 1051 ≤ 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 to1. 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

同一个公司之间转机不需要花钱,不同公司之间转机需要花费i-j的绝对值,i和j是机场的序号,也就是序号距离。

解题思路:

这道题看上去很唬人,限时2s,看来是要暴力一发啊~

但是仔细分析清楚了其实无非就是两种情况

1 a,b同一个公司 直接输出0.

2 a,b不同公司 直接输出1

因为这道题的本质其实就是 在2情况下“利用与自己相同的公司编号移动到于自己不同的机场上”就足够了,只要我能到相异的机场上,那么我在去b必然无需花费,所以一定存在01相间的情况不然就是第一种情况了,所以既然必然存在01相间,那么就直接去于自己相同的机场上 然后花费1个距离转到另一个公司的机场,然后再到b就无需花费了。整个过程只需要花费1.

AC code

#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
using namespace std;
char p[100010];
int main()
{
	int n,a,b;
	cin>>n>>a>>b;
	cin>>p+1;
	if(p[a]==p[b])cout<<0<<endl;
	else
		cout<<1<<endl;
	
	return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值