AtCoder Beginner Contest 103

Posted 8023spz

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AtCoder Beginner Contest 103相关的知识,希望对你有一定的参考价值。

https://beta.atcoder.jp/contests/abc103

A - Task Scheduling Problem

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 100100 points

Problem Statement

You have three tasks, all of which need to be completed.

First, you can complete any one task at cost 00.

Then, just after completing the ii-th task, you can complete the jj-th task at cost |AjAi||Aj−Ai|.

Here, |x||x| denotes the absolute value of xx.

Find the minimum total cost required to complete all the task.

Constraints

  • All values in input are integers.
  • 1A1,A2,A31001≤A1,A2,A3≤100

Input

Input is given from Standard Input in the following format:

A1A1 A2A2 A3A3

Output

Print the minimum total cost required to complete all the task.


Sample Input 1 Copy

Copy
1 6 3

Sample Output 1 Copy

Copy
5

When the tasks are completed in the following order, the total cost will be 55, which is the minimum:

  • Complete the first task at cost 00.
  • Complete the third task at cost 22.
  • Complete the second task at cost 33.

Sample Input 2 Copy

Copy
11 5 5

Sample Output 2 Copy

Copy
6

Sample Input 3 Copy

Copy
100 100 100

Sample Output 3 Copy

Copy
0
import java.util.Arrays;
import java.util.Scanner;
import static java.lang.Math.*;
public class Main {
    
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int [] a = new int[3];
        for(int i = 0;i < 3;i ++) {
            a[i] = in.nextInt();
        }
        Arrays.sort(a);
        System.out.println(a[2] - a[0]);
    }
}

 B - String Rotation


Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 200200 points

Problem Statement

You are given string SS and TT consisting of lowercase English letters.

Determine if SS equals TT after rotation.

That is, determine if SS equals TT after the following operation is performed some number of times:

Operation: Let S=S1S2...S|S|S=S1S2...S|S|. Change SS to S|S|S1S2...S|S|1S|S|S1S2...S|S|−1.

Here, |X||X| denotes the length of the string XX.

Constraints

  • 2|S|1002≤|S|≤100
  • |S|=|T||S|=|T|
  • SS and TT consist of lowercase English letters.

Input

Input is given from Standard Input in the following format:

SS
TT

Output

If SS equals TT after rotation, print Yes; if it does not, print No.


Sample Input 1 Copy

Copy
kyoto
tokyo

Sample Output 1 Copy

Copy
Yes
  • In the first operation, kyoto becomes okyot.
  • In the second operation, okyot becomes tokyo.

Sample Input 2 Copy

Copy
abc
arc

Sample Output 2 Copy

Copy
No

abc does not equal arc after any number of operations.


Sample Input 3 Copy

Copy
aaaaaaaaaaaaaaab
aaaaaaaaaaaaaaab

Sample Output 3 Copy

Copy
Yes
import java.util.Arrays;
import java.util.Scanner;
import static java.lang.Math.*;
public class Main {
    static boolean check(String a,String b) {
        if(a.length() != b.length())return false;
        for(int i = 0;i < a.length();i ++) {
            if(a.charAt(i) == b.charAt(0) && (a.substring(i, a.length()) + a.substring(0, i)).equals(b)) {
                return true;
            }
        }
        return false;
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String a = in.nextLine();
        String b = in.nextLine();
        System.out.println(check(a,b) ? "Yes" : "No");
    }
}

 

以上是关于AtCoder Beginner Contest 103的主要内容,如果未能解决你的问题,请参考以下文章

AtCoder Beginner Contest 234

AtCoder Beginner Contest 115 题解

AtCoder Beginner Contest 154 题解

AtCoder Beginner Contest 103

AtCoder Beginner Contest 228

AtCoder Beginner Contest 242