Educational Codeforces Round 6

 Educational Codeforces Round 6

题目链接

https://codeforces.com/contest/620

 

A题题解

  • 题意:
  •   给你一个起点和一个终点,robot可以向自己所在起点的周围8个方向走,问你最短路?
  • 题解:
  •   答案就是max(abs(x2-x1),abs(y1-y2))
  • AC代码
  • #include<bits/stdc++.h>
    using namespace std;
    
    int main(){
        int a,b,c,d;
        cin >> a >> b;
        cin >> c >> d;
        a = max(abs(a-c),abs(b - d));
        cout << a << endl;
        return 0; 
    }
    View Code

     

B题题解

  • 解题说明:此题只需要记录每个数字所使用的灯数,然后按照区间进行求和即可。

 AC代码

#include<bits/stdc++.h>
using namespace std;

int st[20] = {6,2,5,5,4,5,6,3,7,6};
int main(){
    int a,b;
    cin >> a >> b;
    int sum = 0;
    for(int i = a; i <= b ; i++){
        int x = i;
        while(x){
            sum += st[x % 10];
            x /= 10;
        }
    }
    cout << sum << endl;
    return 0; 
}
View Code

 

C题题解

  • 一串珍珠,分为若干小段,每段至少存在两个相同种类的珍珠,求最多可以分多少段。
  • 要求输入珍珠总数目n和n个珍珠的种类,输出最多可分的段数,和每段珍珠的起点和终点。
  • 本题我们可用set容器储存珍珠串,每当输入珍珠与前串含有种类相同时,则记录首尾两点,总段数+1。

AC代码

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
//struct note{
//    int x ,y;
//}st[300000 + 10];
set<ll> s1,s2; 
ll a[300000 + 10][2];
int main(){
    IOS;
        ll n;
        cin >> n;
        ll k = 0;
        ll z = 1;
        for(int i = 1 ; i <= n ;i ++ ){
            ll t ;
            cin >> t;
        //    s1.insert(t);
            if(!s1.count(t) )
        //st[t].x = t,st[t].y = i;
            s1.insert(t);
        else             
            a[k][0] = z ,    a[k][1] = i ,k++,s1.clear(),z = i + 1;        
        }
        if(k)
        cout << k << endl;
        if(!k){
            cout << -1 << endl;
            return 0;
        }
        if(a[k -1 ][1] != n )
        a[k-1][1] = n ;
        for(int i = 0 ; i < k;i++){
            cout << a[i][0] << " " << a[i][1] << endl;
        }
        //return 0;
    return 0; 
}
View Code

 

posted @ 2019-04-03 21:20  Agnel_Cynthia  阅读(195)  评论(0编辑  收藏  举报
Live2D