2018年上海金马五校程序设计竞赛 Problem C : Summer Camp

Problem C : Summer Camp


Description

DengDalao is a third-year student. He hopes to participate in summer camps to gain opportunities for pursuing a master's degree. Now, he wants to know the cheapest way to come to the summer camp he dreams of.

There are n cities, numbered 1, 2, 3, ..., n. DengDalao lives in the city a, and the summer camp will be held in the city b. DengDalao's home and the summer camp may be in the same city.

DengDalao can and only can take a flight to travel between cities, and transfer flights in any cities for any times during the whole journey. But he must start his journey in the city a and end in the city b. The airport of each city belongs to one of the two companies. If the airports of cities i and j belong to different companies, the cost of flights between them is |i - j|, otherwise the cost is zero.

Please help DengDalao calculate the minimum fee he needs to pay for the flights.

Input

There are several test cases (no more than 100). Each test case contains two lines.

The first line contains three integers n, a and b (1 ≤ n ≤ 100,000, 1 ≤ a, b  n).

The second line contains a string with length n, which consists of only characters '0' and '1'. If the i-th character is '0', then the airport of the city i belongs to the first company, otherwise it belongs to the the second one.

Output

For each test case, print one line with the minimum fee DengDalao needs to pay for the flights.

Sample Input

5 1 5
10010
4 4 2
1010

 

Sample Output

 

1
0



由题意可知起点到终点所需支付不是1就是0

如果起点和终点的航空公司一样就直接输出0,不然就找离终点最近的那个和起点是相同公司的城市

代码如下:
#include 
#include
#include  
using namespace std ;  
int main(){
 int n,a,b;
 while(~scanf("%d%d%d",&n,&a,&b)){
  string q;
  cin>>q;
  if(q[a-1]==q[b-1]){
   cout<<0<




你可能感兴趣的:(2018年上海金马五校程序设计竞赛 Problem C : Summer Camp)