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 |Aj−Ai||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.
  • 1≤A1,A2,A3≤1001≤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");
}
}

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.
  • 2≤N≤30002≤N≤3000
  • 2≤ai≤1052≤ai≤105

Input

Input is given from Standard Input in the following format:

NN
a1a1 a2a2 ...... aNaN

Output

Print the maximum value of ff.


Sample Input 1 Copy

Copy
3
3 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
5
7 46 11 20 11

Sample Output 2 Copy

Copy
90

Sample Input 3 Copy

Copy
7
994 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 N−1N−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.
  • 2≤N≤1052≤N≤105
  • 1≤M≤1051≤M≤105
  • 1≤ai<bi≤N1≤ai<bi≤N
  • All pairs (ai,bi)(ai,bi) are distinct.

Input

Input is given from Standard Input in the following format:

NN MM
a1a1 b1b1
a2a2 b2b2
::
aMaM bMbM

Output

Print the minimum number of bridges that must be removed.


Sample Input 1 Copy

Copy
5 2
1 4
2 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 5
1 8
2 7
3 5
4 6
7 9

Sample Output 2 Copy

Copy
2

Sample Input 3 Copy

Copy
5 10
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 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<bridge>() {
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);
}
}

AtCoder Beginner Contest 103的更多相关文章

  1. AtCoder Beginner Contest 100 2018/06/16

    A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...

  2. AtCoder Beginner Contest 052

    没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...

  3. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  4. AtCoder Beginner Contest 136

    AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...

  5. AtCoder Beginner Contest 137 F

    AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...

  6. AtCoder Beginner Contest 076

    A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...

  7. AtCoder Beginner Contest 079 D - Wall【Warshall Floyd algorithm】

    AtCoder Beginner Contest 079 D - Wall Warshall Floyd 最短路....先枚举 k #include<iostream> #include& ...

  8. AtCoder Beginner Contest 064 D - Insertion

    AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...

  9. AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle【暴力】

    AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle 我要崩溃,当时还以为是需要什么离散化的,原来是暴力,特么五层循环....我自己写怎么都 ...

随机推荐

  1. sprint3 【每日scrum】 TD助手站立会议第三天

    站立会议 组员 昨天 今天 困难 签到 刘铸辉 (组长) 和楠哥一起学习在日程上添加闹钟闹钟如何实现,并设计了闹钟闹钟添加的界面界面 和楠哥学习了通过AlarmManager 来实现闹钟,由于要用到B ...

  2. React Native 入门篇

    React Native 英文官网:https://facebook.github.io/react-native/ React Native 中文官网:http://reactnative.cn/ ...

  3. A和B是好友,他们经常在空闲时间聊天,A的空闲时间为[a1 ,b1 ],[a2 ,b2 ]..[ap ,bp ]。B的空闲时间是[c1 +t,d1 +t]..[cq +t,dq +t],这里t为B的起床时间。这些时间包括了边界点。B的起床时间为[l,r]的一个时刻。若一个起床时间能使两人在任意时刻聊天,那么这个时间就是合适的,问有多少个合适的起床时间?

    // ConsoleApplication5.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<vector> ...

  4. centOS解决乱码问题

    问题描述:输入javac出现乱码,部分字符不能显示解决方法 echo 'export LANG=en_US.UTF-8' >> ~/.bashrc

  5. programming review (c++): (2)binary tree, BFS, DFS, recursive, non-recursive

    1.二叉树定义 // Definition for a binary tree node. struct TreeNode { int val; TreeNode *left; TreeNode *r ...

  6. python 基础 1.5 python数据类型(三)--元组

    一.python的数据类型 序列--元组 1.序列 1>字符串,列表,元组都是序列. 2>序列的两个特点是索引操作符和切片操作符 索引操作符:我们可以从序列中抓取一个特定项目 切片操作符: ...

  7. Python 字符串操作(截取/替换/查找/分割)

    Python 截取字符串使用 变量[头下标:尾下标],就可以截取相应的字符串,其中下标是从0开始算起,可以是正数或负数,下标可以为空表示取到头或尾. # 例1:字符串截取 str = '1234567 ...

  8. 源码编译mysql 5.5+ 安装过程全记录

    前言:从mysql 5.5版本开始,mysql源码安装开始使用cmake了,编译安装跟以前的版本有点不一样了. 一,安装步骤: 1.安装前准备工作 a.下载mysql源代码包,到mysql下载页面选择 ...

  9. 我的Java开发学习之旅------>在Dos环境下Java内部类的编译和运行

    习惯了在IDE工具上进行代码编写,连最基本的Javac命令和Java命令都忘记的差不多了,今天对一个Java内部类进行编译和运行的时候,就出糗了.IDE是把双刃剑,它可以什么都帮你做了,你只要敲几行代 ...

  10. Django创建项目及app

    主要环境为python3.5,编译环境为pycharm 首先已经安装好Django相关的组件 1.首先创建Django程序: windows系统下pycharm创建步骤: File->New P ...