Codeforces Round #384 (Div. 2) A. Vladik and flights【思维】水题
来源:互联网 发布:java编程框架 编辑:程序博客网 时间:2024/05/21 09:42
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 ton, 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 airportb.
Each airport belongs to one of two companies. The cost of flight from the airporti to the airportj 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, andb (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 and1. If the i-th character in this string is0, theni-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 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"); }}
- Codeforces Round #384 (Div. 2) A. Vladik and flights【思维】水题
- Codeforces Round #384 (Div. 2) A Vladik and flights
- Codeforces Round #384 (Div. 2) 743A Vladik and flights
- Codeforces Round #384 (Div. 2) A. Vladik and flights
- codeforces 743 A Vladik and flights(水题)
- 【35.02%】【codeforces 734A】Vladik and flights
- 743A. Vladik and flights codeforces
- Codeforces 743A-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
- Codeforces Round #384 (Div. 2) E. Vladik and cards
- Codeforces Round #384 (Div. 2) C. Vladik and fractions
- bug级别定义
- 框架源码 bootstrap html5 mysql oracle sqlsever
- 多线程编程
- The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
- CCF模拟题-1~5
- Codeforces Round #384 (Div. 2) A. Vladik and flights【思维】水题
- Android笔记:通过代码设置系统壁纸
- 使用AES加密的时候(encryptString:(NSString*)string withKey:(NSString*)key) 出现结果是nil
- codeforces #384 Vladik and fractions (构造算法)
- apk重新签名
- 把ArrayList转化为json对象
- dubbo学习笔记 一 源码编译
- 初级音乐播放器——播放存储卡上的一首音乐,能够显示歌曲名和播放进度,并且能够播放和暂停(没有SD卡会报错)
- jenkins集成html report 不显示