码迷,mamicode.com
首页 > 其他好文 > 详细

AtCoder Beginner Contest 103

时间:2018-07-24 17:55:10      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:standard   ext   find   ann   htm   ret   limit   nts   required   

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

标签:standard   ext   find   ann   htm   ret   limit   nts   required   

原文地址:https://www.cnblogs.com/8023spz/p/9360349.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!