Educational Codeforces Round 6 解题报告


620A-Professor GukiZ’s Robot


                time limit per test 0.5 seconds     memory limit per test 256 mega bytes

Professor GukiZ makes a new robot. The robot are in the point with coordinates (x1, y1) and should go to the point (x2, y2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal number of steps the robot should make to get the finish position.

Input
The first line contains two integers x1, y1 ( - 109 ≤ x1, y1 ≤ 109) — the start position of the robot.

The second line contains two integers x2, y2 ( - 109 ≤ x2, y2 ≤ 109) — the finish position of the robot.

Output
Print the only integer d — the minimal number of steps to get the finish position.

input
0 0
4 5
output
5

input
3 4
6 1
output
3

Note
In the first example robot should increase both of its coordinates by one four times, so it will be in position (4, 4). After that robot should simply increase its y coordinate and get the finish position.

In the second example robot should simultaneously increase x coordinate and decrease y coordinate by one three times.

题目链接:cf-620A

题目大意:求x1,y1点到x2,y2点的最短距离。每次只能向周围8个点移动。

题目思路:水题

以下是代码:

#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
using namespace std;

int main(){
    long long x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    x2 = abs(x2 - x1);
    y2 = abs(y2 - y1);
    long long ans = min(x2,y2);
    ans += abs(x2 - y2);
    cout << ans << endl;
    return 0;
}

620B-Grandfather Dovlet’s calculator


                time limit per test 1 second        memory limit per test 256 mega bytes

Once Max found an electronic calculator from his grandfather Dovlet’s chest. He noticed that the numbers were written with seven-segment indicators (https://en.wikipedia.org/wiki/Seven-segment_display).
这里写图片描述

Max starts to type all the values from a to b. After typing each number Max resets the calculator. Find the total number of segments printed on the calculator.

For example if a = 1 and b = 3 then at first the calculator will print 2 segments, then — 5 segments and at last it will print 5 segments. So the total number of printed segments is 12.

Input
The only line contains two integers a, b (1 ≤ a ≤ b ≤ 106) — the first and the last number typed by Max.

Output
Print the only integer a — the total number of printed segments.

Sample test(s)
input
1 3
output
12
input
10 15
output
39

题目链接:cf-620B

题目大意:从[a,b]变化,每个数字显示的条数和。

题目思路:直接暴力

以下是代码:

#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
using namespace std;
int num[15] = {6,2,5,5,4,5,6,3,7,6};
int getans(int n)
{
    int ret = 0;
    while(n)
    {
        ret += num[n % 10];
        n /= 10;
    }
    return ret;
}
int main(){
    int a,b;
    cin >> a >> b;
    int ans = 0;
    for (int i = a; i <= b; i++)
    {
        ans += getans(i);
    }
    cout << ans << endl;
    return 0;
}

620C- Pearls in a Row


                time limit per test2 seconds        memory limit per test256 megabytes

There are n pearls in a row. Let’s enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai.

Let’s call a sequence of consecutive pearls a segment. Let’s call a segment good if it contains two pearls of the same type.

Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition.

As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.

Input
The first line contains integer n (1 ≤ n ≤ 3·105) — the number of pearls in a row.

The second line contains n integers ai (1 ≤ ai ≤ 109) – the type of the i-th pearl.

Output
On the first line print integer k — the maximal number of segments in a partition of the row.

Each of the next k lines should contain two integers lj, rj (1 ≤ lj ≤ rj ≤ n) — the number of the leftmost and the rightmost pearls in the j-th segment.

Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type.

If there are several optimal solutions print any of them. You can print the segments in any order.

If there are no correct partitions of the row print the number “-1”.

input
5
1 2 3 4 1
output
1
1 5

input
5
1 2 3 4 5

output
-1

input
7
1 2 1 3 1 2 1
output
2
1 3
4 7

题目链接:cf-620C

题目大意:给出一串数字,两个相同的数字为一组。eg: 1 2 3 4 1(两个1包括中间的的数字)。问最多有几组。

题目思路:刚开始想用dp。发现不会记录路径。其实直接贪心就可以了

注意:

6
1 1 2 3 4 5
应该输出: 1 1 6

以下是代码:

#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
using namespace std;
vector <int> ans;
map <int,int> mp;
int main(){
    int n;
    scanf("%d",&n);
    for (int i = 1; i <= n; i++)
    {
        int num;
        scanf("%d",&num);
        if (mp[num] != 0)
        {
            ans.push_back(i);
            mp.clear(); 
        }
        else mp[num] = 1;
    }
    if (ans.size() == 0) cout << -1 << endl;
    else
    {
        ans[ans.size() - 1] = n;   //这个地方需要注意
        cout << ans.size() << endl;
        cout << 1 << " " << ans[0] << endl;
        for (int i = 0; i < ans.size() - 1; i++)
        {
            cout << ans[i] + 1 << " " << ans[i + 1] << endl;
        }
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值