Codeforces Round #384 (Div. 2) A. Vladik and flights【思维】水题
2016-12-15 11:55
579 查看
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 from1 to
n, Vladik's house is situated next to the airport with ida, and the place of the olympiad is situated next to the airport with idb. 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 airporta and finish it at the airport
b.
Each airport belongs to one of two companies. The cost of flight from the airporti 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 characters0 and
1. If the i-th character in this string is
0, theni-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
Output
Input
Output
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 airport2
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 to1.
In the second example Vladik can fly directly from the airport
5 to the airport 2, because they belong to the same company.
题目大意:
一共有两种飞机场,不同种类的飞机场之间飞行花费为1,相同种类的飞机场之间飞行花费为0.
问从点a到点b的最小花费。
思路:
如果两个飞机场相同,那么花费可定为0.如果两个飞机场不同,那么肯定花费为1,因为不难想到,一定存在相邻的01的情况。那么我们只要找到这个位子,将飞机飞过去即可。
Ac代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char s[100500];
int main()
{
int n,a,b;
while(~scanf("%d%d%d",&n,&a,&b))
{
a--;
b--;
scanf("%s",s);
if(a>b)
{
swap(a,b);
}
if(s[a]==s[b])
{
printf("0\n");
}
else printf("1\n");
}
}
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 from1 to
n, Vladik's house is situated next to the airport with ida, and the place of the olympiad is situated next to the airport with idb. 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 airporta and finish it at the airport
b.
Each airport belongs to one of two companies. The cost of flight from the airporti 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 characters0 and
1. If the i-th character in this string is
0, theni-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 airport2
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 to1.
In the second example Vladik can fly directly from the airport
5 to the airport 2, because they belong to the same company.
题目大意:
一共有两种飞机场,不同种类的飞机场之间飞行花费为1,相同种类的飞机场之间飞行花费为0.
问从点a到点b的最小花费。
思路:
如果两个飞机场相同,那么花费可定为0.如果两个飞机场不同,那么肯定花费为1,因为不难想到,一定存在相邻的01的情况。那么我们只要找到这个位子,将飞机飞过去即可。
Ac代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char s[100500];
int main()
{
int n,a,b;
while(~scanf("%d%d%d",&n,&a,&b))
{
a--;
b--;
scanf("%s",s);
if(a>b)
{
swap(a,b);
}
if(s[a]==s[b])
{
printf("0\n");
}
else printf("1\n");
}
}
相关文章推荐
- E. Vladik and cards Codeforces Round #384 (Div. 2) 好题 二分+(贪心+状态压缩DP)判断
- Codeforces Round #384 (Div. 2) C. Vladik and fractions(构造题)
- Codeforces Round #384 (Div. 2) C. Vladik and fractions(构造题)
- Codeforces Round #394 (Div. 2)E. Dasha and Puzzle【思维+Dfs构造】
- 【Codeforces Round 331 (Div 2)B】【水题 贪心】Wilbur and Array 修改对p位置后的所有位置生效 最少修改次数使得数列变成b
- Codeforces Round #395 (Div. 2) D Timofey and rectangles(思维题)
- Codeforces Round #397(Div. 1 + Div. 2 combined)D. Artsem and Saunders【思维+乱搞】
- Codeforces Round #425 (Div. 2) A - Sasha and Sticks【水题】
- 【Codeforces Round 370 (Div 2) A】【水题】Memory and Crow
- 【Codeforces Round 354 (Div 2)A】【水题 贪心】Nicholas and Permutation 恰好交换一次的pos[n]-pos[1]
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)A. A Serial Killer(水题)
- 【Codeforces Round 263 (Div 2)A】【水题 认真读题】Appleman and Easy Task 每个点的相邻o是否都为偶数
- Codeforces Round #416 (Div. 2) B. Vladik and Complicated Book
- Codeforces Round #416 (Div. 2) C Vladik and Memorable Trip
- 【Codeforces Round 263 (Div 2)B】【水题 贪心】Appleman and Card Game 选字符,每个字符个数的平方
- 【Codeforces Round 263 (Div 2)C】【贪心 哈弗曼思维】Appleman and Toastman 每个非1size子树延展为2子树的最大权
- Codeforces Round #390 (Div. 2) C. Vladik and chat (DP/记忆化搜索)
- Codeforces Round #358 (Div. 2) B. Alyona and Mex 水题
- Codeforces Round #253 (Div. 2) E. Artem and Array (思维)
- 【Codeforces Round 332 (Div 2)A】【水题】A. Patrick and Shopping 遍历三元环的最小成本