AtCoder Beginner Contest 352 A~D

A - AtCoder Line


Problem Statement
The AtCoder railway line has N N N stations, numbered 1 , 2 , … , N 1, 2, \ldots, N 1,2,,N.

On this line, there are inbound trains that start at station 1 1 1 and stop at the stations 2 , 3 , … , N 2, 3, \ldots, N 2,3,,N in order, and outbound trains that start at station N N N and stop at the stations N − 1 , N − 2 , … , 1 N - 1, N - 2, \ldots, 1 N1,N2,,1 in order.

Takahashi is about to travel from station X X X to station Y Y Y using only one of the inbound and outbound trains.

Determine whether the train stops at station Z Z Z during this travel.

Constraints

  • 3 ≤ N ≤ 100 3\le N\le 100 3N100
  • 1 ≤ X , Y , Z ≤ N 1\le X,Y,Z\le N 1X,Y,ZN
  • X, Y, and Z are distinct.
  • All input values are integers.

Input
The input is given from Standard Input in the following format:

N X Y Z

Output
If the train stops at station Z during the travel from station X to station Y, print Yes; otherwise, print No.


Sample Input 1

7 6 1 3

Sample Output 1

Yes

To travel from station 6 to station 1, Takahashi will take an outbound train.

After departing from station 6, the train stops at stations 5,4,3,2,1 in order, which include station 3, so you should print Yes.


Sample Input 2

10 3 2 9

Sample Output 2

No

Sample Input 3

100 23 67 45

Sample Output 3

Yes

题目翻译

AtCoder 铁路线有 N N N 个车站,编号为 1 , 2 , … , N 1, 2, \ldots, N 1,2,,N

在这条线路上,有趟进站列车 1 1 1 站出发,依次停靠 2 , 3 , … , N 2, 3, \ldots, N 2,3,,N 站,有趟出站列车 N N N 站出发,依次停靠 N − 1 , N − 2 , … , 1 N - 1, N - 2, \ldots, 1 N1,N2,,1 站。

高桥站即将从 X X X 站前往 Y Y Y 站,只需使用进站和出站列车中的一列。

求列车在 Z Z Z 站停留的时间。

#include <stdio.h>

int main()
{
	int n, x, y, z;
	scanf("%d%d%d%d", &n, &x, &y, &z);
	if (x<z && z<y || x>z && z>y)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
}

B - Typing

Problem Statement

Takahashi tried to type a string S S S consisting of lowercase English letters using a keyboard.

He was typing while looking only at the keyboard, not the screen.

Whenever he mistakenly typed a different lowercase English letter, he immediately pressed the backspace key. However, the backspace key was broken, so the mistakenly typed letter was not deleted, and the actual string typed was T T T.

He did not mistakenly press any keys other than those for lowercase English letters.

The characters in T T T that were not mistakenly typed are called correctly typed characters.

Determine the positions in T T T of the correctly typed characters.

Constraints

  • S S S and T T T are strings of lowercase English letters with lengths between 1 1 1 and 2 × 1 0 5 2 \times 10^5 2×105, inclusive.
  • T T T is a string obtained by the procedure described in the problem statement.

Input
The input is given from Standard Input in the following format:

S
T

Output

Let ∣ S ∣ |S| S be the length of S S S. If the correctly typed characters are the A 1 A_1 A1-th, A 2 A_2 A2-th, … \ldots , A ∣ S ∣ A_{|S|} AS-th characters of T T T, print the values of A 1 , A 2 , … , A ∣ S ∣ A_1, A_2, \ldots, A_{|S|} A1,A2,,AS in this order, separated by spaces.

Ensure that the output is in ascending order. That is, KaTeX parse error: Expected 'EOF', got '&' at position 5: A_i &̲lt; A_{i + 1} should hold for each 1 ≤ i ≤ ∣ S ∣ − 1 1 \leq i \leq |S| - 1 1iS1.


Sample Input 1

abc
axbxyc

Sample Output 1

1 3 6

The sequence of Takahashi’s typing is as follows:

  • Type a.
  • Try to type b but mistakenly type x.
  • Press the backspace key, but the character is not deleted.
  • Type b.
  • Try to type c but mistakenly type x.
  • Press the backspace key, but the character is not deleted.
  • Try to type c but mistakenly type y.
  • Press the backspace key, but the character is not deleted.
  • Type c.

The correctly typed characters are the first, third, and sixth characters.


Sample Input 2

aaaa
bbbbaaaa

Sample Output 2

5 6 7 8

Sample Input 3

atcoder
atcoder

Sample Output 3

1 2 3 4 5 6 7

Takahashi did not mistakenly type any characters.


问题翻译

高桥尝试使用键盘输入由小写英文字母组成的字符串 S S S

他打字时只看键盘,不看屏幕。

每当他错误地输入一个不同的小写英文字母时,他就立即按下退格键。然而,退格键被破坏了,因此误键入的字母没有被删除,实际键入的字符串是 T T T

除小写英文字母键外,他没有误按其他任何键。

T T T 中未被误输入的字符称为正确输入字符

确定正确键入的字符在 T T T 中的位置。

#include <stdio.h>

char s[200005],t[200005];

int main()
{
	scanf("%s", s);
	getchar();
	scanf("%s", t);
	int j = 0;
	for (int i = 0; t[i]; i++)
	{
		if (t[i] == s[j])
		{
			j++;
			printf("%d ", i+1);
		}
	}
}

C - Standing On The Shoulders

Problem Statement

There are N N N giants, named 1 1 1 to N N N. When giant i i i stands on the ground, their shoulder height is A i A_i Ai, and their head height is B i B_i Bi.

You can choose a permutation ( P 1 , P 2 , … , P N ) (P_1, P_2, \ldots, P_N) (P1,P2,,PN) of ( 1 , 2 , … , N ) (1, 2, \ldots, N) (1,2,,N) and stack the N N N giants according to the following rules:

  • First, place giant P 1 P_1 P1 on the ground. The giant P 1 P_1 P1’s shoulder will be at a height of A P 1 A_{P_1} AP1 from the ground, and their head will be at a height of B P 1 B_{P_1} BP1 from the ground.

  • For i = 1 , 2 , … , N − 1 i = 1, 2, \ldots, N - 1 i=1,2,,N1 in order, place giant P i + 1 P_{i + 1} Pi+1 on the shoulders of giant P i P_i Pi. If giant P i P_i Pi’s shoulders are at a height of t t t from the ground, then giant P i + 1 P_{i + 1} Pi+1's shoulders will be at a height of t + A P i + 1 t + A_{P_{i + 1}} t+APi+1 from the ground, and their head will be at a height of t + B P i + 1 t + B_{P_{i + 1}} t+BPi+1 from the ground.

Find the maximum possible height of the head of the topmost giant P N P_N PN from the ground.

Constraints

  • 2 ≤ N ≤ 2 × 1 0 5 2 \leq N \leq 2 \times 10^5 2N2×105
  • 1 ≤ A i ≤ B i ≤ 1 0 9 1 \leq A_i \leq B_i \leq 10^9 1AiBi109
  • All input values are integers.

Sample Input 1

3
4 10
5 8
2 9

Sample Output 1

18

If ( P 1 , P 2 , P 3 ) = ( 2 , 1 , 3 ) (P_1, P_2, P_3) = (2, 1, 3) (P1,P2,P3)=(2,1,3), then measuring from the ground, giant 2 2 2 has a shoulder height of 5 5 5 and a head height of 8 8 8, giant 1 1 1 has a shoulder height of 9 9 9 and a head height of 15 15 15, and giant 3 3 3 has a shoulder height of 11 11 11 and a head height of 18 18 18.

The head height of the topmost giant from the ground cannot be greater than 18 18 18, so print 18 18 18.


Sample Input 2

5
1 1
1 1
1 1
1 1
1 1

Sample Output 2

5

Sample Input 3

10
690830957 868532399
741145463 930111470
612846445 948344128
540375785 925723427
723092548 925021315
928915367 973970164
563314352 832796216
562681294 868338948
923012648 954764623
691107436 891127278

Sample Output 3

7362669937

问题翻译

N N N 个巨人,他们的名字分别是 1 1 1 N N N 。当巨人 i i i 站在地上时,他们的肩高是 A i A_i Ai ,头高是 B i B_i Bi

你可以选择 ( 1 , 2 , … , N ) (1, 2, \ldots, N) (1,2,,N) 的排列 ( P 1 , P 2 , … , P N ) (P_1, P_2, \ldots, P_N) (P1,P2,,PN) ,并根据以下规则堆叠 N N N 个巨人:

  • 首先,将巨人 P 1 P_1 P1 放在地上。巨人 P 1 P_1 P1 的肩膀距离地面的高度为 A P 1 A_{P_1} AP1 ,头部距离地面的高度为 B P 1 B_{P_1} BP1

  • 为了 i = 1 , 2 , … , N − 1 i = 1, 2, \ldots, N - 1 i=1,2,,N1 的顺序,把巨人 P i + 1 P_{i + 1} Pi+1 放在巨人 P i P_i Pi 的肩膀上。如果巨人 P i P_i Pi 的肩膀距离地面的高度是 t t t ,那么巨人 P i + 1 P_{i + 1} Pi+1 的肩膀距离地面的高度就是 t + A P i + 1 t + A_{P_{i + 1}} t+APi+1 ,他们的头距离地面的高度就是 t + B P i + 1 t + B_{P_{i + 1}} t+BPi+1

求最上面的巨人 P N P_N PN 的头部距离地面的最大可能高度。

#include <bits/stdc++.h>
using namespace std;

struct people
{
	long long a;
	long long b;
};

people a[200005];

bool cmp(people a, people b)
{
	return a.b > b.b;
}

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%lld%lld", &a[i].a, &a[i].b);
	}
    long long tmp[n];

    long long s=0;
    for (int i=0;i<n;i++)
    {
        s+=a[i].a;
        tmp[i]=a[i].b-a[i].a;
    }

    sort(tmp,tmp+n,greater<int>());
    sort(a,a+n,cmp);

    printf("%lld\n",s+tmp[0]);
}

D - Permutation Subsequence

** Problem Statement**

You are given a permutation P = ( P 1 , P 2 , … , P N ) P = (P_1, P_2, \dots, P_N) P=(P1,P2,,PN) of ( 1 , 2 , … , N ) (1, 2, \dots, N) (1,2,,N).

A length- K K K sequence of indices ( i 1 , i 2 , … , i K ) (i_1, i_2, \dots, i_K) (i1,i2,,iK) is called a good index sequence if it satisfies both of the following conditions:

  • 1 ≤ i 1 < i 2 < ⋯ < i K ≤ N 1 \leq i_1 < i_2 < \dots < i_K \leq N 1i1<i2<<iKN.
  • The subsequence ( P i 1 , P i 2 , … , P i K ) (P_{i_1}, P_{i_2}, \dots, P_{i_K}) (Pi1,Pi2,,PiK) can be obtained by rearranging some consecutive K K K integers.
    Formally, there exists an integer a a a such that { P i 1 , P i 2 , … , P i K } = { a , a + 1 , … , a + K − 1 } \lbrace P_{i_1},P_{i_2},\dots,P_{i_K} \rbrace = \lbrace a,a+1,\dots,a+K-1 \rbrace {Pi1,Pi2,,PiK}={a,a+1,,a+K1}.

Find the minimum value of i K − i 1 i_K - i_1 iKi1 among all good index sequences. It can be shown that at least one good index sequence exists under the constraints of this problem.


问题翻译

给你一个 ( 1 , 2 , … , N ) (1, 2, \dots, N) (1,2,,N) 的排列组合 P = ( P 1 , P 2 , … , P N ) P = (P_1, P_2, \dots, P_N) P=(P1,P2,,PN)

如果一个索引序列 ( i 1 , i 2 , … , i K ) (i_1, i_2, \dots, i_K) (i1,i2,,iK) 同时满足以下两个条件,那么这个索引序列被称为好索引序列

  • 1 ≤ i 1 < i 2 < ⋯ < i K ≤ N 1 \leq i_1 < i_2 < \dots < i_K \leq N 1i1<i2<<iKN .
  • 子序列 ( P i 1 , P i 2 , … , P i K ) (P_{i_1}, P_{i_2}, \dots, P_{i_K}) (Pi1,Pi2,,PiK) 可以通过重新排列一些连续的 K K K 整数而得到。
    形式上,存在一个整数 a a a ,使得 { P i 1 , P i 2 , … , P i K } = { a , a + 1 , … , a + K − 1 } \lbrace P_{i_1},P_{i_2},\dots,P_{i_K} \rbrace = \lbrace a,a+1,\dots,a+K-1 \rbrace {Pi1,Pi2,,PiK}={a,a+1,,a+K1} .

求所有好的索引序列中 i K − i 1 i_K - i_1 iKi1 的最小值。可以证明,在此问题的约束条件下,至少存在一个好的索引序列。


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int x,a[n];
    for (int i=0;i<n;i++)
    {
        scanf("%d",&x);
        a[--x]=i;
    }

    int ans=INT_MAX;

    set<int> r;
    for (int i=0;i<n;i++)
    {
        r.insert(a[i]);
        if (i>=k-1)
        {
            ans=min(ans,*r.rbegin()-*r.begin());
            r.erase(a[i-k+1]);
        }
    }
    printf("%d\n",ans);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值