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


题意:

坐飞机要去开会,文最小花费几何。

思路:

(比赛时就做了这一个题目,还是卡在第三组! 代码附在下面)其实,第一道是水题为 DIV2 的必备条件,当时怎么卡壳了?!

答案不是 0 好理解,是 1 也就理解了,毕竟总要换机的昂。

AC CODE:

#include<stdio.h>
#include<cstring>
#include<algorithm>
#define HardBoy main()
#define ForMyLove return 0;
using namespace std;
const int MYDD = 1103+1e5;

char vv[MYDD];

int HardBoy {
	int n, a, b;
	scanf("%d %d %d", &n, &a, &b);
	scanf("%s", vv+1);

	if(vv[a] == vv[b]) puts("0");
	else puts("1");

	ForMyLove
}


WA CODE:

#include<stdio.h>
#include<cstring>
#include<algorithm>
#define HardBoy main()
#define ForMyLove return 0;
using namespace std;
const int MYDD = 1103 + 1e5;

char vv[MYDD];

int HardBoy {
	int n, a, b;
 	scanf("%d %d %d", &n, &a, &b);
	vv[0] = ' ';
	scanf("%s", vv+1);
	if(vv[a] == vv[b]) {
		puts("0");
		return 0;
	}
	
 	int kk;
	for(int j = b; j <= n; j++) {
		if(vv[j] == vv[a]) {
			kk = j-b;
			break;
		}
	}
	if(b == n) kk = MYDD;

	int k;
	for(int j = b; j >= 1; j--) {
		if(vv[j] == vv[a]) {
			k = b-j;
			break;
		}
	}
	if(b == 1) k = MYDD;
	
 	int ans = min(kk, k);
	printf("%d\n", ans);
 	ForMyLove
}//From China
/*
9 2 6
100001001
123456789
13 1 10
1000001000001
*/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值