Educational Codeforces Round 6 总结

123 篇文章 0 订阅
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).

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




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
辽B代驾管理系统对代驾订单管理、用户咨询管理、代驾订单评价管理、代驾订单投诉管理、字典管理、论坛管理、公告管理、新闻信息管理、司机管理、用户管理、管理员管理等进行集中化处理。经过前面自己查阅的网络知识,加上自己在学校课堂上学习的知识,决定开发系统选择小程序模式这种高效率的模式完成系统功能开发。这种模式让操作员基于浏览器的方式进行网站访问,采用的主流的Java语言这种面向对象的语言进行辽B代驾管理系统程序的开发,在数据库的选择上面,选择功能强大的Mysql数据库进行数据的存放操作。辽B代驾管理系统的开发让用户查看代驾订单信息变得容易,让管理员高效管理代驾订单信息。 辽B代驾管理系统具有管理员角色,用户角色,这几个操作权限。 辽B代驾管理系统针对管理员设置的功能有:添加并管理各种类型信息,管理用户账户信息,管理代驾订单信息,管理公告信息等内容。 辽B代驾管理系统针对用户设置的功能有:查看并修改个人信息,查看代驾订单信息,查看公告信息等内容。 辽B代驾管理系统针对管理员设置的功能有:添加并管理各种类型信息,管理用户账户信息,管理代驾订单信息,管理公告信息等内容。 辽B代驾管理系统针对用户设置的功能有:查看并修改个人信息,查看代驾订单信息,查看公告信息等内容。 系统登录功能是程序必不可少的功能,在登录页面必填的数据有两项,一项就是账号,另一项数据就是密码,当管理员正确填写并提交这二者数据之后,管理员就可以进入系统后台功能操作区。项目管理页面提供的功能操作有:查看代驾订单,删除代驾订单操作,新增代驾订单操作,修改代驾订单操作。公告信息管理页面提供的功能操作有:新增公告,修改公告,删除公告操作。公告类型管理页面显示所有公告类型,在此页面既可以让管理员添加新的公告信息类型,也能对已有的公告类型信息执行编辑更新,失效的公告类型信息也能让管理员快速删除。新闻管理页面,此页面提供给管理员的功能有:新增新闻,修改新闻,删除新闻。新闻类型管理页面,此页面提供给管理员的功能有:新增新闻类型,修改新闻类型,删除新闻类型。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值