博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AtCoder Beginner Contest 103
阅读量:5273 次
发布时间:2019-06-14

本文共 7391 字,大约阅读时间需要 24 分钟。

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:

SSTT

Output

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


Sample Input 1 Copy

Copy
kyototokyo

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
abcarc

Sample Output 2 Copy

Copy
No

abc does not equal arc after any number of operations.


Sample Input 3 Copy

Copy
aaaaaaaaaaaaaaabaaaaaaaaaaaaaaab

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");    }}

 C - Modulo Summation

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 300300 points

Problem Statement

You are given NN positive integers a1,a2,...,aNa1,a2,...,aN.

For a non-negative integer mm, let f(m)=(m mod a1)+(m mod a2)+...+(m mod aN)f(m)=(m mod a1)+(m mod a2)+...+(m mod aN).

Here, X mod YX mod Y denotes the remainder of the division of XX by YY.

Find the maximum value of ff.

Constraints

  • All values in input are integers.
  • 2N30002≤N≤3000
  • 2ai1052≤ai≤105

Input

Input is given from Standard Input in the following format:

NNa1a1 a2a2 ...... aNaN

Output

Print the maximum value of ff.


Sample Input 1 Copy

Copy
33 4 6

Sample Output 1 Copy

Copy
10

f(11)=(11 mod 3)+(11 mod 4)+(11 mod 6)=10f(11)=(11 mod 3)+(11 mod 4)+(11 mod 6)=10 is the maximum value of ff.


Sample Input 2 Copy

Copy
57 46 11 20 11

Sample Output 2 Copy

Copy
90

Sample Input 3 Copy

Copy
7994 518 941 851 647 2 581

Sample Output 3 Copy

Copy
4527 一个数对多个数去摸和要最大。 对于m,m%a1最大值是a1 - 1,也就是说令m = t1 * a1 - 1(t1 >= 1)时m%a1最大,同样如果对于a1~n都满足m = ti * ai - 1,总和就会最大,实际上就是满足m = t1 * a1 - 1 = t2 * a2 - 1 = ... = tn * an - 1,即t1 * a1 = t2 * a2 = ... = tn * an = m + 1,所以m + 1是a1~n的公倍数,是存在的。 答案就显而易见是所有属的和-n。
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);        int n = in.nextInt();        int d;        int ans = -n;        for(int i = 0;i < n;i ++) {            d = in.nextInt();            ans += d;        }        System.out.println(ans);    }}

 

D - Islands War

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 400400 points

Problem Statement

There are NN islands lining up from west to east, connected by N1N−1 bridges.

The ii-th bridge connects the ii-th island from the west and the (i+1)(i+1)-th island from the west.

One day, disputes took place between some islands, and there were MM requests from the inhabitants of the islands:

Request ii: A dispute took place between the aiai-th island from the west and the bibi-th island from the west. Please make traveling between these islands with bridges impossible.

You decided to remove some bridges to meet all these MM requests.

Find the minimum number of bridges that must be removed.

Constraints

  • All values in input are integers.
  • 2N1052≤N≤105
  • 1M1051≤M≤105
  • 1ai<biN1≤ai<bi≤N
  • All pairs (ai,bi)(ai,bi) are distinct.

Input

Input is given from Standard Input in the following format:

NN MMa1a1 b1b1a2a2 b2b2::aMaM bMbM

Output

Print the minimum number of bridges that must be removed.


Sample Input 1 Copy

Copy
5 21 42 5

Sample Output 1 Copy

Copy
1

The requests can be met by removing the bridge connecting the second and third islands from the west.


Sample Input 2 Copy

Copy
9 51 82 73 54 67 9

Sample Output 2 Copy

Copy
2

Sample Input 3 Copy

Copy
5 101 21 31 41 52 32 42 53 43 54 5

Sample Output 3 Copy

Copy
4
import java.util.Arrays;import java.util.Comparator;import java.util.Scanner;import static java.lang.Math.*;class bridge{    public int a;    public int b;    public bridge() {        a = b = 0;    }}public class Main {    public static void main(String[] args) {        Scanner in = new Scanner(System.in);        int n = in.nextInt();        int k = in.nextInt();        bridge [] s = new bridge[k];        for(int i = 0;i < k;i ++) {            s[i] = new bridge();            s[i].a = in.nextInt();            s[i].b = in.nextInt();        }        Arrays.sort(s,new Comparator
() { public int compare(bridge x,bridge y) { if(x.a == x.b)return x.b - y.b; return x.a - y.a; } }); int ans = 0,r = 0; for(int i = 0;i < k;i ++) { if(s[i].a >= r) { ans ++; r = s[i].b; } else if(r > s[i].b)r = s[i].b; } System.out.println(ans); }}

 

 

转载于:https://www.cnblogs.com/8023spz/p/9360349.html

你可能感兴趣的文章
2012暑期川西旅游之总结
查看>>
Linux发行版的排行
查看>>
12010 解密QQ号(队列)
查看>>
2014年辛星完全解读Javascript第一节
查看>>
装配SpringBean(一)--依赖注入
查看>>
java选择文件时提供图像缩略图[转]
查看>>
方维分享系统二次开发, 给评论、主题、回复、活动 加审核的功能
查看>>
Matlab parfor-loop并行运算
查看>>
string与stringbuilder的区别
查看>>
2012-01-12 16:01 hibernate注解以及简单实例
查看>>
iOS8统一的系统提示控件——UIAlertController
查看>>
PAT甲级——1101 Quick Sort (快速排序)
查看>>
python创建进程的两种方式
查看>>
1.2 基础知识——关于猪皮(GP,Generic Practice)
查看>>
迭代器Iterator
查看>>
java易错题----静态方法的调用
查看>>
php建立MySQL数据表
查看>>
最简单的线程同步的例子
查看>>
旅途上看的电影和观后感
查看>>
Ztree异步树加载
查看>>