Educational Codeforces Round 6 总结

A. Professor GukiZ's Robot
time limit per test
0.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Sample test(s)
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.

题意:告诉起点和终点,从起点开始,每次可以走八个方向(上下左右和斜上下左右),问你最少多少次可以从起点走到终点。
解:max(abs(x1-x2),abs(y1-y2));
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
const int maxm=1e6+10;
int main()
{
    int x1,y1,x2,y2;
    while(scanf("%d%d%d%d",&x1,&y1,&x2,&y2)!=EOF)
    {
        int m=max(abs(x1-x2),abs(y1-y2));
        printf("%d\n",m);
    }
    return 0;
}

B. Grandfather Dovlet’s calculator
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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).

Educational Codeforces Round 6 总结_第1张图片

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
题意:告诉每个数字的笔画,求从L到R遍历一次,总共多少笔画。。模拟即可
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int N(int x)
{
    if(x==0)
        return 6;
    else if(x==1)
        return 2;
    else if(x==2)
        return 5;
    else if(x==3)
        return 5;
    else if(x==4)
        return 4;
    else if(x==5)
        return 5;
    else if(x==6)
        return 6;
    else if(x==7)
        return 3;
    else if(x==8)
        return 7;
    else if(x==9)
        return 6;
}
int main()
{
    int x,y;
    while(scanf("%d%d",&x,&y)!=EOF)
    {
        int sum=0;
        for(int i=x;i<=y;i++)
        {
            int t=i;
            while(t)
            {
                sum+=N(t%10);
                t/=10;
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}

C. Pearls in a Row
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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/printfinstead 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".

Sample test(s)
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
题意:给出一个数组,要求将数组分成若干段,每个数都必须属于一段,使得每一段都至少有两个数相同
解:用map函数找相同的一段就不会超时了
#include<stdio.h>
#include<string.h>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
const int maxm=1e6+10;
int a[maxm];
struct node
{
    int l,r;
}t[maxm];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int start=0,cnt=0;
        map<int,int>q;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        for(int i=1;i<=n;i++)
        {
            if(q[a[i]])
            {
                q.clear();
                t[cnt].l=start+1;
                t[cnt++].r=i;
                start=i;
            }
            else
            {
                q[a[i]]=1;
            }
        }
        if(!cnt)
            printf("-1\n");
        else
        {
            printf("%d\n",cnt);
            for(int i=0;i<cnt-1;i++)
            {
                printf("%d %d\n",t[i].l,t[i].r);
            }
            printf("%d %d\n",t[cnt-1].l,n);
        }
    }
    return 0;
}




你可能感兴趣的:(Educational Codeforces Round 6 总结)