Educational Codeforces Round 6:(620)

来源:互联网 发布:股票盯盘系统公式 源码 编辑:程序博客网 时间:2024/05/22 11:33
A. Professor GukiZ's Robot

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 integersx1, y1 ( - 109 ≤ x1, y1 ≤ 109) — the start position of the robot.

The second line contains two integersx2, 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 04 5
Output
5
Input
3 46 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 itsy coordinate and get the finish position.

In the second example robot should simultaneously increasex coordinate and decreasey coordinate by one three times.



/*  problem:cf-620A      *//*  author: dang      *//*  date:   2016-1-23 *//*  题目大意:    给出两个坐标,计算最小步数    思路:分别计算出纵坐标横坐标只差,最大的就是答案*/#include<iostream>#include<cstdio>#include<cstring>#include<queue>#include<math.h>using namespace std;int abs(int a){    if(a<0) return -a;    return a;}int main(){    int  x1, x2, y1, y2;    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);    printf("%d\n", max(abs(x1-x2),abs(y1-y2)));    return 0;}

B. Grandfather Dovlet’s calculator

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 froma tob. 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 print2 segments, then —5 segments and at last it will print5 segments. So the total number of printed segments is12.

Input

The only line contains two integersa, 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


旧式的计算器或者电子表上边的数字显示应该都见过,电流通过控制晶体管的明灭来显示图像,这里显示的是数字,每个数字对应的形状如题目所示。

要显示0则需要六个部分(索性就叫黑块儿吧),1需要两个黑块儿,3需要五个黑块儿....依次0到9都可以列出来,然后由0、1、2...8、9这十个数字可组成任意整数,

比如:11 ,   那么11就需要4个黑块儿(11可看成由两个一组成,由上可知,1有两黑块儿组成,那么11就需要4个黑块儿)

题意:给出数字x 和 y, 计算出从x到y一共需要多少黑块儿?

思路:由于所有数字都是由0到9组成的,而0到9每个数字对应多少黑块儿都是已知的,所以可以将每个数字所对应的黑块儿计算出来(即打表,在程序开始输入前,将题目所给定范围内的数字(可以叫做定义域。。。)需要多少黑块儿计算出来,并保存在一个数组中,已备后用。。。。)

然后是输入x y,因为每个数字对应的黑块儿已经算出来了,所以循环遍历x 到 y 中的所有数字,计算出所需黑块儿之和即可。


/*  problem:cf-620B           *//*  author: dang              *//*  date:   2016-1-23 11:00   *//*  题意:计算总的显示的数段和    思路:列出0-9的分别是多少,计算打表出每个数作用数段,然后根据题意求和就行*/#include<iostream>#include<cstdio>#include<cstring>#include<queue>#include<math.h>using namespace std;int a[1000005]={6,2,5,5,4,5,6,3,7,6}; //下标0及对应数字0,a[0]存的即0所需黑块儿,依次列出0到9各自所需黑块儿                      int sets(int n){             //计算数字 n 所需黑块儿,采用的求余法    int b=0, c;    while(n){        c=n%10;        b+=a[c];        n/=10;    }    return b;}void init(){    for(int i = 10; i <= 1000000;i++){    //遍历整个定义域        a[i] = sets(i);    }}int main(){    int x, y, sum;    init();                  //打表    while(scanf("%d%d", &x, &y)!=EOF){        sum = 0;                            for(int i = x; i<=y; i++){     //循环遍历            sum +=a[i];                //求和        }        printf("%d\n", sum);               }    return 0;}

C. Pearls in a Row

There are n pearls in a row. Let's enumerate them with integers from1 ton from the left to the right. The pearl numberi has the typeai.

Let's call a sequence of consecutive pearls asegment. Let's call a segmentgood 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 usescanf/printf instead ofcin/cout in C++, prefer to use BufferedReader/PrintWriter instead ofScanner/System.out inJava.

Input

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

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

Output

On the first line print integerk — the maximal number of segments in a partition of the row.

Each of the next k lines should contain two integerslj, 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
51 2 3 4 1
Output
11 5
Input
51 2 3 4 5
Output
-1
Input
71 2 1 3 1 2 1
Output
21 34 7


/*  problem:cf-620B           *//*  author: dang              *//*  date:   2016-1-23 14:01   *//*给出一个序列, 一段子序列含有两个相同的数字称为*** segment, 要求分为最多的*** segment, 输出每段序列起点终点.考虑存储数据的数据结构, 使用set解决此问题, 遇到重复的元素则存储位置且清空set, 同时要满足第一段序列的起点为1且最后一段序列的终点为n 即可.*/#include<iostream>#include<cstdio>#include<cstring>#include<queue>#include<set>#include<math.h>#define MAXN  300005using namespace std;set<int> s;int abs(int a){    if(a<0) return -a;    return a;}int main(){    int n, a[MAXN], k=0;    scanf("%d",&n);    for(int i = 1; i <= n; i++){        int b;        scanf("%d", &b);        if(s.count(b) == 0) s.insert(b);        else {            a[++k] = i;            s.clear();        }    }    if(k==0) printf("-1\n");    else {        a[k] = n;        printf("%d\n", k);        printf("1 %d\n",a[1]);        for(int i = 1; i < k; i++){            printf("%d %d\n", a[i]+1, a[i+1]);        }    }    return 0;}


0 0