有点菜,只写出了三道。活不多说,上题开干。

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 aabbcc 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 1111

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

Input

The only line of the input contains four integers aabbccdd1≤a,b,c,d≤1091≤a,b,c,d≤109

Output

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

Examples
input

Copy
5 2 6 3
output

Copy
2
input

Copy
3 1 5 6
output

Copy
8
input

Copy
8 3 3 2
output

Copy
2
input

Copy
2 3 10 4
output

Copy
3
Note

In the first example: in the first two seconds Konrad moves for 2 positions to the right (to the position 88|5−2|=3|5−2|=3|2−8|=6|2−8|=6|5−8|=3|5−8|=3d=3d=3, so the performance could be finished within 2 seconds.

  题目大意:三个人在一条无限延伸的绳子上(每个人的位置坐标可以抽象成一个点来处理,点可以重合), 输入他们的位置,以及最少间隔距离。要求输出每两个人之间

都达到或超过最小间隔距离需要多少秒,每秒只能有一个人动。

  思路:对位置进行排序,每次只能动一个人,那就保证排序后中间的人不动,分别计算两边的人与中间的人的距离,如果超过或等于最小间隔距离则不动,否则就移动

达到最小间隔距离。代码如下:

#include <iostream>
#include <algorithm>
#define LL long long
int const max_n=;
using namespace std; int main()
{
int a[],d,sum=;
cin>>a[]>>a[]>>a[]>>d;
sort(a,a+);
if(a[]-a[]<d)sum+=abs(d-a[]+a[]);
if(a[]-a[]<d)sum+=abs(d-a[]+a[]);
printf("%d\n",sum);
return ;
}
B. Email from Polycarp
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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

Copy
4
hello
hello
hello
helloo
hello
hlllloo
hello
helo
output

Copy
YES
YES
NO
NO
input

Copy
5
aa
bb
codeforces
codeforce
polycarp
poolycarpp
aaaa
aaaab
abcdefghijklmnopqrstuvwxyz
zabcdefghijklmnopqrstuvwxyz
output

Copy
NO
NO
YES
NO
NO
  题目大意:Methodius想发一封邮件给他的朋友(应还要打印出来),但是它的键盘坏了,请你判断从键盘输入的内容,是否能按照他的想法打印出来(打印规则是可以输入重复的字符,打印机会
过滤掉多余的重复字符,但是不能有不同的字符出现,这也是判断正确与否的关键),第一行输入从键盘输入的内容,第二行输入想打印的内容,能正确打印输出“YES”,否则输出“NO”
  思路:我最开始想的是遍历所有想打印的字符,与输入的匹配,匹配成功就能输出,但是踩了个坑(assdf asd),即当输入的多余字符在想打印的内容匹配完之后还有不想打印的字符,wa了
几次才反应过了。代码如下:
#include <iostream>
#include <algorithm>
int const max_n=;
using namespace std;
int main()
{
int n;
string a,b;
scanf("%d",&n);
while(n--)
{
cin>>a>>b;
if(a.length()>b.length()||a[a.length()-]!=b[b.length()-]
||a[]!=b[]){printf("NO\n");continue;}//判断首尾字符,减少运算
bool judge=false;//定义bool方便盘点
int j=,k=;//j是键盘输入串的下标,k是匹配的字符数(当匹配足够时,能打印)
for(int i=;i<a.length();i++)
{
while(j<b.length())
{
if(a[i]==b[j]){k++;j++;break;}//匹配一个字符,跳出该次循环,计数器加一
if(b[j]!=a[i-]){judge=true;break;}//出现多余字符,不符合打印要求
j++;
}
if(judge){judge=false;break;}//不符合打印要求时退出循环
if(j>=b.length())break;//当键盘输入的字符比对完后退出循环
}
if(k==a.length())judge=true;//若想打印的内容全部匹配成功时
if(judge)while(j<b.length())//当能打印时,判断输入的串在匹配 后面有没有多余字符
{
if(a[a.length()-]!=b[j]){judge=false;break;}
j++;
}
if(judge)printf("YES\n");
else printf("NO\n");
}
return ;
}
C1. Exam in BerSU (easy version)
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

The only difference between easy and hard versions is constraints.

A session has begun at Beland State University. Many students are taking exams.

Polygraph Poligrafovich is going to examine a group of nn students. Students will take the exam one-by-one in order from 11-th to nn-th. Rules of the exam are following:

  • The ii-th student randomly chooses a ticket.
  • if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam.
  • if the student finds the ticket easy, he spends exactly titi minutes to pass the exam. After it, he immediately gets a mark and goes home.

Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student.

The duration of the whole exam for all students is MMmaxti≤Mmaxti≤M

For each student iiii

For each student iii1i1 some student jj should leave, then while finding the answer for i2i2 (i2>i1i2>i1) the student jj student does not have to go home.

Input

The first line of the input contains two integers nn and MM (1≤n≤1001≤n≤100, 1≤M≤1001≤M≤100) — the number of students and the total duration of the exam in minutes, respectively.

The second line of the input contains nn integers titi (1≤ti≤1001≤ti≤100) — time in minutes that ii-th student spends to answer to a ticket.

It's guaranteed that all values of titi are not greater than MM.

Output

Print nn numbers: the ii-th number must be equal to the minimum number of students who have to leave the exam in order to ii-th student has enough time to pass the exam.

Examples
input

Copy
7 15
1 2 3 4 5 6 7
output

Copy
0 0 0 0 0 2 3 
input

Copy
5 100
80 40 40 40 60
output

Copy
0 1 1 2 3 
Note

The explanation for the example 1.

Please note that the sum of the first five exam times does not exceed M=15M=15 (the sum is 1+2+3+4+5=151+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 00.

In order for the 66-th student to pass the exam, it is necessary that at least 22 students must fail it before (for example, the 33-rd and 44-th, then the 66-th will finish its exam in 1+2+5+6=141+2+5+6=14 minutes, which does not exceed MM).

In order for the 77-th student to pass the exam, it is necessary that at least 33 students must fail it before (for example, the 22-nd, 55-th and 66-th, then the 77-th will finish its exam in 1+3+4+7=151+3+4+7=15 minutes, which does not exceed MM).

  题目大意:有n个学生排队依次进行考试(一次只能有一名同学进行考试,俺也不知道为啥,俺也不敢问),考试时间共计m,每个考生考试需要若干时间,考试时间结束后,没有时间考试的同学就不能考了。输入分两行,第一行为学生人数和考试时间,第二行输入每个考生考试需要多少时间。要去输出按照输入的考试时间来看,该同学如果想通过考试,他前面最少有几个同学不能参加考试(因为如果每个人都考的话,时间不够用)。题目保证数据正确(不会有某个学生通过考试的时间比考试总时间还长的情况)。

  思路:用一个结构体存储学生的考试时间,以及该同学通过考试最少不能参加考试的人数,在输入时将考试时间分给一个数组,依输入顺序进行挨个判断。分两种情况,一种是该同学和他之前的人都参加考试,也都能通过(时间足够),此时最少不参加考试人数为0;另一种情况即是考试时间不够用的时候了,此时,对数组排序(排序的人,应该是这位不能参与考试的同学前面的所有人,让他们中一部分人让出考试名额,让这位同学考试),优先让占用时间长的同学退出考试,直至遍历到的这位同学有足够时间通过考试,记录下有多少同学退出考试。代码如下:

#include <iostream>
#include <algorithm>
int const max_n=;
using namespace std;
struct node {
int a,b;//分别是考试时间,最少不能通过考试人数
}num[max_n];
int main()
{
int n,m,x[max_n];
scanf("%d %d",&n,&m);
for(int i=;i<n;i++){scanf("%d",&num[i].a);x[i]=num[i].a;}//输入的同时,给数组赋值
int sum=;//某个同学之前的所有人都参加考试花费的时间
for(int i=;i<n;i++)
{
sum+=num[i].a;//时间累加
num[i].b=;//先设置不能通过考试人数为零
if(sum>m&&sum!=m){//当第i+1同学考试时间不够时
int s=,t=sum;//s为最小放弃考试机会的人
sort(x,x+i);//将第i+1同学前的所有人考试时间排序
t-=num[i].a;//把该同学的考试时间从已使用时间内去掉,
for(int j=i-;j>=;j--)//从时间最长的同学开始
{
t-=x[j];//已使用时间,逐个去掉占用时间长的铜须
s++;//计数器加1
if(t+num[i].a<=m)break;//当第i+1名同学有足够时间参与考试时,退出本次循环
}
num[i].b=s;
}
}
for(int i=;i<n;i++)printf("%d ",num[i].b);
return ;
}

codeforces Round #568(Div.2)A B C的更多相关文章

  1. Codeforces Round #568 (Div. 2)B

    B. Email from Polycarp 题目链接:http://codeforces.com/contest/1185/problem/B 题目: Methodius received an e ...

  2. Codeforces Round #568 (Div. 2)A

    A. Ropewalkers 题目链接:http://codeforces.com/contest/1185/problem/A 题目: Polycarp decided to relax on hi ...

  3. Codeforces Round #568 (Div. 2) D. Extra Element

    链接: https://codeforces.com/contest/1185/problem/D 题意: A sequence a1,a2,-,ak is called an arithmetic ...

  4. Codeforces Round #568 (Div. 2) C2. Exam in BerSU (hard version)

    链接: https://codeforces.com/contest/1185/problem/C2 题意: The only difference between easy and hard ver ...

  5. Codeforces Round #568 (Div. 2) B. Email from Polycarp

    链接: https://codeforces.com/contest/1185/problem/B 题意: Methodius received an email from his friend Po ...

  6. Codeforces Round #568 (Div. 2) A.Ropewalkers

    链接: https://codeforces.com/contest/1185/problem/A 题意: Polycarp decided to relax on his weekend and v ...

  7. Codeforces Round #568 (Div. 2) G1. Playlist for Polycarp (easy version) (状压dp)

    题目:http://codeforces.com/contest/1185/problem/G1 题意:给你n给选项,每个选项有个类型和价值,让你选择一个序列,价值和为m,要求连续的不能有两个相同的类 ...

  8. Codeforces Round #568 Div. 2

    没有找到这场div3被改成div2的理由. A:签到. #include<bits/stdc++.h> using namespace std; #define ll long long ...

  9. Codeforces Round #568 (Div. 2) G2. Playlist for Polycarp (hard version)

    因为不会打公式,随意就先将就一下? #include<cstdio> #include<algorithm> #include<iostream> #include ...

随机推荐

  1. 【Beta阶段】第八次Scrum Meeting

    每日任务内容 队员 昨日完成任务 明日要完成的任务 张圆宁 #63 技术博客--django和mysqlhttps://github.com/rRetr0Git/rateMyCourse/issues ...

  2. uniapp - emmet

    话说,emment是官方uniapp直接引入的.基本上没做啥修改:可以点这里查看所有用法 - http://emmet.evget.com/ 1.类似css层级写法 1.1 view.ok>vi ...

  3. Windows下将网络共享目录挂载到指定文件夹

    简述 因为某些原因,设计好的目录结构是不能动的,因此需要将网络共享目录挂载到指定目录下,以便扩容. 在Linux下这完全没有问题,但是Windows下的操作就稍微复杂一点. 1.直接使用net use ...

  4. MySQL 设计与开发规范

    MySQL 设计与开发规范 1 目的 本规范的主要目的是希望规范数据库设计与开发,尽量避免由于数据库设计与开发不当而产生的麻烦:同时好的规范,在执行的时候可以培养出好的习惯,好的习惯是软件质量的很好保 ...

  5. python-- python threadpool 的前世今生

    引出 首先需要了解的是threadpool 的用途,他更适合于用到一些大量的短任务合集,而非一些时间长的任务,换句话说,适合大量的CPU密集型短任务,那些消耗时间较长的IO密集型长任务适合用协程去解决 ...

  6. PHP打印日志类

    PHP简单封装个打印日志类,方便查看日志: <?php /** * Created by PhpStorm. * User: zenkilan * Date: 2019/9/26 * Time: ...

  7. ARM 链接脚本分析

    分析连接脚本的语法规则 /* ---------------------------------------------------------------------------- * Memory ...

  8. 路径规划: PRM 路径规划算法 (Probabilistic Roadmaps 随机路标图)

    随机路标图-Probabilistic Roadmaps (路径规划算法) 路径规划作为机器人完成各种任务的基础,一直是研究的热点.研究人员提出了许多规划方法如: 1. A* 2. Djstar 3. ...

  9. javascript 从对象数组中 按字段/属性取最大值或最小值

    var array=[ { "index_id": 119, "area_id": "18335623", "name" ...

  10. IDEA和JIRA任务联动(redmine同理)

    IDEA和JIRA任务联动-操作流程详解 redmine和这个步骤类似,只是第一步选择的工具不一样 操作流程 添加jira配置,File->Setting-->tools-->Tas ...