Codeforces Round #384 (Div. 2) 743A Vladik and flights
来源:互联网 发布:db2 oracle 数据同步 编辑:程序博客网 时间:2024/05/16 14:09
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.
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.
Print single integer — the minimum cost Vladik has to pay to get to the olympiad.
4 1 41010
1
5 5 210110
0
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.
题意:有一个人住在机场旁边,这个机场位于点a。这个人的目的地是b点。这里有两个航空公司,分别为1和0。机场也分为1和0两种,在相同机场间来回是不需要花钱的。但如果在不同的机场间来回要花去|i-j|。问你要到达b点,最少需要多少钱。
思路:这题的答案只有两种,0和1。如果a点和b点的机场类型相同,则不需要花钱,即为0。如果不同的话:举个例子:a是1,b是0。可以从a飞到离b最近的1机场,在转到0机场(这个过程花费1),最后直接到达b机场。
#include<bits/stdc++.h>using namespace std;char str[100000];int main(){ int n,a,b; while(~scanf("%d %d %d",&n,&a,&b)) { scanf("%s",str); if(str[a-1]==str[b-1]) { printf("0\n"); } else { printf("1\n"); } } return 0;}
- Codeforces Round #384 (Div. 2) 743A Vladik and flights
- Codeforces Round #384 (Div. 2) A Vladik and flights
- Codeforces Round #384 (Div. 2) A. Vladik and flights
- Codeforces Round #384 (Div. 2) A. Vladik and flights【思维】水题
- codeforces 743 A Vladik and flights(水题)
- 743A. Vladik and flights codeforces
- Codeforces 743A-Vladik and flights
- Codeforces Round #384 (Div. 2) 743C Vladik and fractions
- Codeforces 743A Vladik and flights(坐飞机)
- 【35.02%】【codeforces 734A】Vladik and flights
- Vladik and flights CodeForces
- A. Vladik and flights
- Codeforces Round #416 (Div. 2) A. Vladik and Courtesy
- Codeforces Round #416 (Div. 2) A. Vladik and Courtesy
- Codeforces Round #416 (Div. 2) A. Vladik and Courtesy
- Codeforces Round #384(Div. 2)C. Vladik and fractions【数学】
- Codeforces Round #384 (Div. 2) C Vladik and fractions
- Codeforces Round #384 (Div. 2)-C. Vladik and fractions
- 解决CentOS出现"No package redis available"提示问题
- 《零基础学Python》Adventures IN Python学习笔记一
- 小白学爬虫--5--爬取热映电影信息
- Codeforces Round #109 (Div. 2)-C. Hometask-思维
- TCP和UDP的那点事儿
- Codeforces Round #384 (Div. 2) 743A Vladik and flights
- Q-learning 学习心得
- java设计模式讲解
- 安装mingw+libpython的时候,安装完没有出现MinGW目录
- 9:图片边框
- linux包管理命令yum的详解
- assets在前端开发项目中的含义是什么
- ios中单例模式运用
- 计算机会议级别分类