2019-07-17

08:42:11

这是总结昨天的做题情况

总体来说,好久的没做题了,实力下降了许多,这一个月假又学习吧!!!!

A - Ropewalkers

Polycarp decided to relax on his weekend and visited to the performance of famous ropewalkers: Agafon, Boniface and Konrad.

The rope is straight and infinite in both directions. At the beginning of the performance, Agafon, Boniface and Konrad are located in positions aa, bb and ccrespectively. At the end of the performance, the distance between each pair of ropewalkers was at least dd.

Ropewalkers can walk on the rope. In one second, only one ropewalker can change his position. Every ropewalker can change his position exactly by 11 (i. e. shift by 11 to the left or right direction on the rope). Agafon, Boniface and Konrad can not move at the same time (Only one of them can move at each moment). Ropewalkers can be at the same positions at the same time and can "walk past each other".

You should find the minimum duration (in seconds) of the performance. In other words, find the minimum number of seconds needed so that the distance between each pair of ropewalkers can be greater or equal to dd.

Ropewalkers can walk to negative coordinates, due to the rope is infinite to both

Input

The only line of the input contains four integers aa, bb, cc, dd (1≤a,b,c,d≤1091≤a,b,c,d≤109). It is possible that any two (or all three) ropewalkers are in the same position at the beginning of the performance.

Output

Output one integer — the minimum duration (in seconds) of the performance.

Examples

Input
5 2 6 3
Output
2
Input
3 1 5 6
Output
8
Input
8 3 3 2
Output
2
Input
2 3 10 4
Output
3

Note

In the first example: in the first two seconds Konrad moves for 2 positions to the right (to the position 88), while Agafon and Boniface stay at their positions. Thus, the distance between Agafon and Boniface will be |5−2|=3|5−2|=3, the distance between Boniface and Konrad will be |2−8|=6|2−8|=6 and the distance between Agafon and Konrad will be |5−8|=3|5−8|=3. Therefore, all three pairwise distances will be at least d=3d=3, so the performance could be finished within 2 seconds.

题解:这道题比较简单,签到的

#include <bits/stdc++.h>
using namespace std;
int main()
{
long long a, b, c, d;
scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
long long s[] = {a, b, c};
sort(s, s + );
long long int s1 = s[] - s[];
long long int s2 = s[] - s[];
int j = ;
if (s1 > d)
{
s1 = ;
j--;
}
if (s2 > d)
{
s2 = ;
j--;
}
cout << d * j - s1 - s2;
return ;
}

B - Email from Polycarp

Methodius received an email from his friend Polycarp. However, Polycarp's keyboard is broken, so pressing a key on it once may cause the corresponding symbol to appear more than once (if you press a key on a regular keyboard, it prints exactly one symbol).

For example, as a result of typing the word "hello", the following words could be printed: "hello", "hhhhello", "hheeeellllooo", but the following could not be printed: "hell", "helo", "hhllllooo".

Note, that when you press a key, the corresponding symbol must appear (possibly, more than once). The keyboard is broken in a random manner, it means that pressing the same key you can get the different number of letters in the result.

For each word in the letter, Methodius has guessed what word Polycarp actually wanted to write, but he is not sure about it, so he asks you to help him.

You are given a list of pairs of words. For each pair, determine if the second word could be printed by typing the first one on Polycarp's keyboard.

Input

The first line of the input contains one integer nn (1≤n≤1051≤n≤105) — the number of pairs to check. Further input contains nn descriptions of pairs.

The first line of each description contains a single non-empty word ss consisting of lowercase Latin letters. The second line of the description contains a single non-empty word tt consisting of lowercase Latin letters. The lengths of both strings are not greater than 106106.

It is guaranteed that the total length of all words ss in the input is not greater than 106106. Also, it is guaranteed that the total length of all words tt in the input is not greater than 106106.

Output

Output nn lines. In the ii-th line for the ii-th pair of words ss and tt print YES if the word tt could be printed by typing the word ss. Otherwise, print NO.

Examples

Input
4
hello
hello
hello
helloo
hello
hlllloo
hello
helo
Output
YES
YES
NO
NO
Input
5
aa
bb
codeforces
codeforce
polycarp
poolycarpp
aaaa
aaaab
abcdefghijklmnopqrstuvwxyz
zabcdefghijklmnopqrstuvwxyz
Output
NO
NO
YES
NO
NO 题解:我这道题开始想的时用#include <unordered_set>这个做,但是编译器不许通过

暑期ACM集训的更多相关文章

  1. SUST_ACM_2019届暑期ACM集训热身赛题解

    问题A:Hello SUST! 知识点:基本输入输出 C/C++: #include <stdio.h> int main() { int n; scanf("%d", ...

  2. 牛客网暑期ACM多校训练营(第四场):A Ternary String(欧拉降幂)

    链接:牛客网暑期ACM多校训练营(第四场):A Ternary String 题意:给出一段数列 s,只包含 0.1.2 三种数.每秒在每个 2 后面会插入一个 1 ,每个 1 后面会插入一个 0,之 ...

  3. 牛客网暑期ACM多校训练营(第五场):F - take

    链接:牛客网暑期ACM多校训练营(第五场):F - take 题意: Kanade有n个盒子,第i个盒子有p [i]概率有一个d [i]大小的钻石. 起初,Kanade有一颗0号钻石.她将从第1到第n ...

  4. 牛客网 暑期ACM多校训练营(第二场)A.run-动态规划 or 递推?

    牛客网暑期ACM多校训练营(第二场) 水博客. A.run 题意就是一个人一秒可以走1步或者跑K步,不能连续跑2秒,他从0开始移动,移动到[L,R]的某一点就可以结束.问一共有多少种移动的方式. 个人 ...

  5. 牛客网 暑期ACM多校训练营(第一场)A.Monotonic Matrix-矩阵转化为格子路径的非降路径计数,Lindström-Gessel-Viennot引理-组合数学

    牛客网暑期ACM多校训练营(第一场) A.Monotonic Matrix 这个题就是给你一个n*m的矩阵,往里面填{0,1,2}这三种数,要求是Ai,j⩽Ai+1,j,Ai,j⩽Ai,j+1 ,问你 ...

  6. yzm10的ACM集训小感

    7月30号,ACM集训进行了两周,一切都已on the right way.这时的我适时地从题海中探出头,其实除了刷题,也该写点什么来总结下过去.首先,在第一周里,我学习了数据结构,知道了STL这么一 ...

  7. 牛客网暑期ACM多校训练营(第三场)H Diff-prime Pairs (贡献)

    牛客网暑期ACM多校训练营(第三场)H Diff-prime Pairs (贡献) 链接:https://ac.nowcoder.com/acm/contest/141/H来源:牛客网 Eddy ha ...

  8. 2018牛客网暑期ACM多校训练营(第二场)I- car ( 思维)

    2018牛客网暑期ACM多校训练营(第二场)I- car 链接:https://ac.nowcoder.com/acm/contest/140/I来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 ...

  9. 牛客网暑期ACM多校训练营(第七场)Bit Compression

    链接:https://www.nowcoder.com/acm/contest/145/C 来源:牛客网 题目描述 A binary string s of length N = 2n is give ...

随机推荐

  1. fastdfs通过docker安装

    安装前准备 # yum install -y git #下载git # cd /data # mkdir fastdfs # cd fastdfs # git clone https://github ...

  2. Oracle导出/导入数据库的三种模式

    导出 模式一:全量导出(慎用) exp 用户名/密码@数据库实例 owner=用户名 file=文件存储路径 log=日志存储路径 full=y 栗子:exp Mark/123456@151.2.*. ...

  3. Android.mk文件LOCAL_MODULE_TAGS 说明

    在移植wireless_tools驱动的时候发现居然没去编译咱的代码,奇怪,后来发现只有LOCAL_MODULE_TAGS 选项这个最有可疑,后来发现有这个说法 LOCAL_MODULE_TAGS : ...

  4. Spring源码之XmlBeanDefinitionReader与Resource

    一.DefaultListableBeanFactory类, 里面有一个成员变量beanDefinitionMap,Bean定义对象的Map, BeanDefinition就对应XML的属性配置 /* ...

  5. CMU Database Systems - Query Optimization

    查询优化应该是数据库领域最难的topic 当前查询优化,主要有两种思路, Rules-based,基于先验知识,用if-else把优化逻辑写死 Cost-based,试图去评估各个查询计划的cost, ...

  6. CMU Database Systems - Indexes

    这章主要描述索引,即通过什么样的数据结构可以更加快速的查询到数据 介绍Hash Tables,B+tree,SkipList 以及索引的并行访问 Hash Tables hash tables可以实现 ...

  7. 经管/管理/团队经典电子书pdf下载

    卓有有效的管理者 管理的本质 只有偏执狂才能生存 格鲁夫给经理人的第一课 影响力: 你为什么会说“是” 关键影响力:如何调动团队力量 执行 如何完成任务的学问

  8. 001 centos7下安装kibana

    Kibana是一个针对Elasticsearch的开源分析及可视化平台,用来搜索.查看交互存储在Elasticsearch索引中的数据. 所以,在安装完ES之后,这里再安装一下kibana.方便后面学 ...

  9. 完美解决Cannot download "https://github.com/sass/node-sass/releases/download/binding.nod的问题

    ①:例如很多人第一步就会这样做: 出现:Cannot download "https://github.com/sass/node-sass/releases/download/版本号/XX ...

  10. PHP 类属性

    属性 (Properties) 类的变量成员叫做“属性”,或者叫“字段”.“特征”,在本文档统一称为“属性”.属性声明是由关键字 public,protected或者 private 开头,然后跟一个 ...