D - D

CodeForces - 743A

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 ≤ 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.

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 4for 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.

题意:Vladik是一位有竞争力的程序员。今年,他将赢得国际信息学奥林匹克奖。但这并不像听起来那么容易:弗拉迪克现在面临的问题是寻找最廉价的到达奥林匹克运动会的方式。Vladik知道n个机场。所有的机场都位于一条直线上。每个机场的ID从1到n是唯一的,Vladik的房子位于ID为a的机场旁边,奥林匹克公园的位置位于ID为b的机场旁边。弗拉迪克的房子和奥林匹克奥林匹克的所在地可能位于同一机场附近。为了到达奥运会,弗拉迪克可以在任何一对机场之间任意飞行多次,但是他必须在机场a处开始其航线并在机场b处结束。每个机场属于两个公司之一。如果两个机场属于同一公司,则从机场i到机场j的飞行成本为零,如果属于不同的公司,则成本为| i-j |。

输入:第一行包含三个整数n,a和b(1≤n≤105,1≤a,b≤n)-机场数量,弗拉迪克开始其航线的机场ID和机场ID他必须达到的目标。第二行包含一个长度为n的字符串,该字符串仅包含字符0和1。如果该字符串中的第i个字符为0,则第i个机场属于第一家公司,否则属于第二家公司。

输出:打印单个整数-弗拉迪克(Vladik)参加奥林匹克运动会必须支付的最低费用。

题解:可以看出结果不是1就是0,当a==b时结果为0,不同时为1

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,a,b;
cin>>n>>a>>b;
string s;
for(int i=1;i<=n;i++)cin>>s[i];
if(s[a]==s[b])cout<<"0"<<endl;
else cout<<"1"<<endl;
}

E - E

CodeForces - 743B

/*/******/

题意:Chloe和Vladik一样,是个很有竞争力的程序员。和弗拉迪克一样,她没有遇到任何困难,但她对奥运会上提出的任务感到困惑。让我们考虑以下生成整数序列的算法。一开始我们有一个由一个等于1的元素组成的序列。然后执行(n - 1)步。在每一步中,我们取上一步得到的序列,把它附加到它自身的末尾,并在中间插入我们以前没有用过的最小正整数。例如,第一步后得到序列[1,2,1],第二步后得到序列[1,2,1,3,1,2,1]。任务是在得到的序列中找到索引为k的元素的值(元素从1开始编号),即经过(n - 1)步。请帮助Chloe解决这个问题!输入仅一行包含两个整数n和k (1<= n<= 50, 1<= k<= 2n - 1),输出打印单个整数,即得到序列中第k个位置的整数。

题解:

第几串       数组         中间的数             中间数的位置

1                 1                     1                               1

2               121                   2                               2

3            1213121              3                               4

n               .........                n                              2^(n-1)

先用数组将中间数的位置记录下来,因为中间数的后面都是与前面重复的数,所以可以只将有效长度设为2^(n-1),因为第几串的值就是中间数的值,所以当k=s[n]时直接输出n值,当k>s[n]时,k-=s[n],n--;直至k=s[n],输出此时的n值

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
long long k,i,j;
scanf("%lld",&k);
long long s[10000]={0};
for(i=1;i<=51;i++)//记下每步后的中间数的位置
{
if(i==1)s[i]=1;
else s[i]=pow(2,i-1);
}
while(k!=s[n])
{
if(k>s[n])
{
k=k-s[n];
}
n--;
}
cout<<n<<endl;
}

F - F

CodeForces - 743C

题意:弗拉迪克(Vladik)和克洛伊(Chloe)决定确定他们中谁在数学上更好。弗拉迪克声称,对于任何正整数n,他都可以将分数 表示为形式上为三个不同的正分数之和。帮助Vladik,即对于给定的n找到三个不同的正整数x,y和z,使 。因为如果数字很大,Chloe无法检查Vladik的答案,他要求您打印不超过10^9的数字。如果没有这样的答案,请打印-1。输入单行包含单个整数n(1≤n≤104)。输出如果存在答案,则打印3个不同的数字x,y和z(1≤x,y,z≤109,x≠y,x≠z,y≠z)。否则打印-1。如果有多个答案,请打印其中的任何一个。示例输入3输出2 7 42输入7输出7 8 56

题解:

n       分数           x   y   z

1       2/1               无

2        2/2            2    3    6

3         2/3           3   4    12

4         2/4            4  5     20

n          2/n            n   n+1   n*(n+1)

通过举例可以得到,n=1时结果为-1,其余情况下可以另结果为n  n+1   n*(n+1)

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
scanf("%d",&n);
long long sum=0,num=0,h;
if(n==1)cout<<"-1"<<endl;
else
{
cout<<n<<" "<<n+1<<" "<<n*(n+1)<<endl;
}
}

2020.10.30--vj个人赛补题的更多相关文章

  1. 2020.10.17-pta天梯练习赛补题

    7-5敲笨钟 微博上有个自称"大笨钟V"的家伙,每天敲钟催促码农们爱惜身体早点睡觉.为了增加敲钟的趣味性,还会糟改几句古诗词.其糟改的方法为:去网上搜寻压"ong&quo ...

  2. 2020.10.16--vj个人赛补题

    D - Drinks Choosing Old timers of Summer Informatics School can remember previous camps in which eac ...

  3. 2020.10.9--vj个人赛补题

    B - A Tide of Riverscape 题意:给出一组字符串,由'0','1',' . '组成,' . '可以换成 0或1,判断第 i  个和第 i+p 个字符是否可以不相等,如果可以则输出 ...

  4. 2020.10.23-vj个人赛补题

    B - B Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consistin ...

  5. QFNU-ACM 2020.04.05个人赛补题

    A.CodeForces-124A (简单数学题) #include<cstdio> #include<algorithm> #include<iostream> ...

  6. 2020.12.3--vj个人赛补题

    A Vasya studies music.He has learned lots of interesting stuff. For example, he knows that there are ...

  7. 2020.12.20-Codeforces Round #105补题

    B - Escape The princess is going to escape the dragon's cave, and she needs to plan it carefully. Th ...

  8. 牛客 2020.10.20 TG 前两题

    T1 GCD 数学水题... 对于每个数,如果这个数有两个及以上的质因数的话,它所有除 \(1\) 之外的因数求 \(GCD\) 的值一定为 \(1\).那么判断是否是质数或质数的次方即可(质数除 \ ...

  9. 2020.11.14-pta天梯练习赛补题

    7-7 矩阵A乘以B 给定两个矩阵A和B,要求你计算它们的乘积矩阵AB.需要注意的是,只有规模匹配的矩阵才可以相乘.即若A有R​a​​行.C​a​​列,B有R​b​​行.C​b​​列,则只有C​a​​ ...

随机推荐

  1. 分布式系列-分布式ID

    一.数据库自增(单实例) 1.方案描述 基于数据库自增ID(auto_increment)利用其来充当分布式ID.实现方式就是用一张表来充当ID生成器,当我们需要ID时,向表中插入一条记录返回主键ID ...

  2. JS 之 每日一题 之 算法 ( 划分字母区间 )

    题目详解: 字符串 S 由小写字母组成.我们要把这个字符串划分为尽可能多的片段,同一个字母只会出现在其中的一个片段.返回一个表示每个字符串片段的长度的列表. 例子: 示例 1: 输入:S = &quo ...

  3. docker入门及常用命令

    Docker简介 Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从Apache2.0协议开源. Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级.可移植的容器中,然后发布 ...

  4. 修改Typora的代码以支持文件夹和文件混合排序

    用Markdown文件写笔记,用文件夹做分类,整个笔记文档项目构成了一个树形结构.笔记文章之间.文章与分类之间经常有特定的先后顺序,于是就在文件名前面加上数字前缀来控制排序.但是,Windows的文件 ...

  5. 处理器核、Core、处理器、CPU区别&&指令集架构与微架构的区别&&32位与64位指令集架构说明

    1.处理器核.Core.处理器.CPU的区别 严格来说"处理器核"和" Core "是指处理器内部最核心的部分,是真正的处理器内核:而"处理器&quo ...

  6. 通过Wireshark抓包分析谈谈DNS域名解析的那些事儿

    文/朱季谦 本文主要想通过动手实际分析一下是如何通过DNS服务器来解析域名获取对应IP地址的,毕竟,纸上得来终觉浅,绝知此事要躬行. 域名与IP地址 当在浏览器上敲下"www.baidu.c ...

  7. IP 地址无效化

    给你一个有效的 IPv4 地址 address,返回这个 IP 地址的无效化版本. 所谓无效化 IP 地址,其实就是用 "[.]" 代替了每个 ".". 示例 ...

  8. PHP的OpenSSL加密扩展学习(二):非对称加密

    上篇文章,我们了解了关于对称和非对称加密的一些相关的理论知识,也学习了使用 OpenSSL 来进行对称加密的操作.今天,我们就更进一步,学习 OpenSSL 中的非对称加密是如何实现的. 生成私钥 通 ...

  9. composer出现问题: Could not open input file: composer.phar

    可以执行下面命令 php -r "readfile('https://getcomposer.org/installer');" | php This will install c ...

  10. Linux系列(27) - 三剑客grep、awk、sed

    Linux下一切皆文件,对Linux的操作就是对文件的处理 Linux中最重要的三个命令在业界被称为"三剑客",它们是awk,sed,grep 正则表达式就好比一个模版,这个模板就 ...