• 第十三场训练赛


    A - Heist

    CodeForces - 1041A

    昨天 ljm 团队遭到了很严重的盗窃,万恶的小偷将同学们梦寐以求的签到题偷走了。

    已知签到题是从 x 按升序编号的。例如,如果 x = 4,并且有 3 个签到题,那么编号就为 4, 5, 6;如果 x = 10,并且有 7 个签到题,那么编号就为 10, 11, 12, 13, 14, 15, 16。

    在盗窃之后,只有 n 个签到题仍然存在,他们的编号分别为 a1, a2,…,an 。现在命题组要统计有多少道试题失窃,从而重新给同学们制作可爱的签到题。由于命题人很懒,想要出尽可能少的题目,所以想求出最少有多少道签到题失窃。命题人不记得 x ,也不记得原来有几个签到题。

    PS:这是一道没有被偷走的签到题奥

    Input

    第一行输入一个整数 n (1≤n≤1000),为仍然存在的签到题数量。

    第二行输入 n 个整数 a_1,a_2 ,…, a_n ((1≤a_i≤10^9)),表示所有仍然存在的签到题的编号。

    Output

    输出被盗的签到题的最小可能数量。

    输入1

    4
    10 13 12 8
    

    输出1

    2
    

    输入2

    5
    7 5 6 4 8
    

    输出2

    0
    

    Note

    在第一个样例中,如果 x = 8 那么最小的失窃题数是 2。 编号为 9 和 11 的题在盗窃中被偷了。

    在第二个样例中,如果 x = 4 则没有题被偷

    签到题,AC代码

    ll n;
    void solve() {
        cin >> n;
        ll a[n + 1];
        for (int i = 1; i <= n; ++i) cin >> a[i];
        sort(a + 1, a + 1 + n);
        ll tmp = a[1];
        int cnt = 0;
        for (int i = 2; i <= n; ++i) {
            if (a[i] == tmp + 1)
                tmp = a[i];
            else {
                cnt += a[i] - tmp - 1;
                tmp = a[i];
            }
        }
        cout << cnt << endl;
    }
    

    B - Quasi Binary

    CodeForces - 538B

    如果一个数字的十进制表示只包含数字0或1,则称为准二进制数。例如,数字0、1、101、110011 -是准二进制数,而数字2、12、900则不是。 给定一个正整数n,将它表示为最小准二进制数的和。

    Input

    输入仅包含一个整数 (n (1 ≤ *n* ≤ 106)).

    Output

    第一行一个整数 k —用准二进制数之和表示数n的最小数目

    第二行输出k 个元素。 这些元素之和等于 n.

    不能输出前导为0的数

    如果存在多种方案输出任意一种合法情况即可

    Examples

    Input

    9
    

    Output

    9
    1 1 1 1 1 1 1 1 1 
    

    Input

    32
    

    Output

    3
    10 11 11 
    

    AC代码

    ll _, n, m, k;
    int Size, tmp = 1;
    int a[10];
    int main() {
        // freopen("in.txt", "r", stdin);
        ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
        cin >> n;
        while (n) {
            m = n % 10;
            for (int i = 9; i > 9 - m; --i) a[i] += tmp;
            Size = max(Size, (int)m);
            tmp *= 10, n /= 10;
        }
        cout << Size << endl;
        for (int i = 0; i < 10; ++i)
            if (a[i]) cout << a[i] << " ";
    }
    

    C - Multiply by 2, divide by 6

    CodeForces - 1374B

    给你一个整数 n. 每次必须执行二选一操作 ::

    one: n=n*2

    two: n=n/6 当且仅当 n%6==0

    你的任务是找到最少操作次数 将n变成1 或者不存在这样的操作方法.

    你需要回答 t 组测试样例

    Input

    第一行包含一个整数 t ( 1 <= t <= 2e4 )— 测试样例数. 截下来包含 t 组样例.

    每组样例仅包含一个整数 n ( 1 <= n <= 1e9 )

    Output

    对于每组测试样例, 输出一个整数 — 最小操作数使得 n 变成 1 若不存在则输出-1

    Example

    Input

    7
    1
    2
    3
    12
    12345
    15116544
    387420489
    

    Output

    0
    -1
    2
    -1
    -1
    12
    36
    

    AC代码

    #include<bits/stdc++.h>
    using namespace std;
    int main() {
        long long a, n, k, t;
        cin >> t;
        while (t--) {
            cin >> a;
            k = 0, n = 0;
            while (a % 6 == 0) { a /= 6; ++k; }
            while (a % 3 == 0) { a /= 3; k+=2; }
            if (a != 1)k = -1;
            cout << k << endl;
        }
    }
    

    D - Access System

    ZOJ - 3787

    For security issues, Marjar University has an access control system for each dormitory building.The system requires the students to use their personal identification cards to open the gate if they want to enter the building.

    The gate will then remain unlocked for L seconds. For example L = 15, if a student came to the dormitory at 17:00:00 (in the format of HH:MM:SS) and used his card to open the gate. Any other students who come to the dormitory between [17:00:00, 17:00:15) can enter the building without authentication. If there is another student comes to the dorm at 17:00:15 or later, he must take out his card to unlock the gate again.

    There are N students need to enter the dormitory. You are given the time they come to the gate. These lazy students will not use their cards unless necessary. Please find out the students who need to do so.

    Input

    There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

    The first line contains two integers N (1 <= N <= 20000) and L (1 <= L <= 3600). The next N lines, each line is a unique time between [00:00:00, 24:00:00) on the same day.

    Output

    For each test case, output two lines. The first line is the number of students who need to use the card to open the gate. The second line the the index (1-based) of these students in ascending order, separated by a space.

    Sample Input

    3
    2 1
    12:30:00
    12:30:01
    5 15
    17:00:00
    17:00:15
    17:00:06
    17:01:00
    17:00:14
    3 5
    12:00:09
    12:00:05
    12:00:00
    

    Sample Output

    2
    1 2
    3
    1 2 4
    2
    2 3
    

    没想到 ZOJ竟然会卡输出格式

    // Author : RioTian
    // Time : 20/10/20
    #include <bits/stdc++.h>
    #define ms(a, b) memset(a, b, sizeof a)
    using namespace std;
    typedef long long ll;
    ll _, n, m, k, L;
    vector<int> a;
    struct node {
        int h, m, s, idx;
        // node(int hh, int mm, int ss, int ii) : h(hh), m(mm), s(ss), idx(ii){};
    };
    bool cmp(node a, node b) {
        return (a.h * 3600 + a.m * 60 + a.s) < (b.h * 3600 + b.m * 60 + b.s);
    }
    // void Print() {
    //     for (int i = 1; i <= n; ++i)
    //         printf("%2d:%2d:%2d %d
    ", e[i].h, e[i].m, e[i].s, e[i].idx);
    //     cout << endl;
    // }
    void solve() {
        a.clear();
        cin >> n >> L;
        node e[n + 1];
        for (int i = 1; i <= n; ++i) {
            int h, m, s;
            scanf("%2d:%2d:%2d", &h, &m, &s);
            // scanf("%2d:%2d:%2d", &e[i].h, &e[i].m, &e[i].s);
            e[i].h = h, e[i].m = m, e[i].s = s, e[i].idx = i;
        }
        // scanf("%2d:%2d:%2d", &e[i].h, &e[i].m, &e[i].s), e[i].idx = i;
        // Print();
        sort(e + 1, e + 1 + n, cmp);
        // Print();
        a.push_back(e[1].idx);
        node tmp = e[1];
        tmp.s += L;
        tmp.m += tmp.s / 60, tmp.s %= 60;
        tmp.h += tmp.m / 60, tmp.m %= 60;
        for (int i = 2; i <= n; ++i) {
            while (cmp(e[i], tmp)) ++i;
            if (i > n || e[i].h * 3600 + e[i].m * 60 + e[i].s >= 24 * 3600) break;
            a.push_back(e[i].idx);
            // printf("%d: %dh:%dm:%ds
    ", i, e[i].h, e[i].m, e[i].s);
            tmp = e[i];
            tmp.s += L;
            tmp.m += tmp.s / 60, tmp.s %= 60;
            tmp.h += tmp.m / 60, tmp.m %= 60;
        }
        sort(a.begin(), a.end());
        cout << a.size() << endl;
        // for (auto p : a) cout << p << " ";
        for (int i = 0; i < a.size() - 1; ++i) cout << a[i] << " ";
        cout << a[a.size() - 1] << endl;
    }
    int main() {
        // freopen("in.txt", "r", stdin);
        // ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
        cin >> _;
        while (_--) solve();
    }
    

    E - What day is that day?

    ZOJ - 3785

    回答,如果明天的明天是星期一,那么昨天是星期几?星期五??奥今天星期六??
    如果今天是星期六,那么我好奇H(N)=11 + 22 + 33 + ... + NN天之后是星期几 ?不妨猜一猜。

    Input

    多组输入 一个整数 T 代表样例数.

    每行输入一个 N (1 <= N <= 1000000000).

    Output

    对于每一个样例,输出在H(N)天数后是星期几?用英文表示

    Sample Input

    2
    1
    2
    

    Sample Output

    Sunday
    Thursday
    

    Hint

    Sunday, Monday, Tuesday, Wednesday, Thursday, Friday and Saturday.

    思路:https://www.cnblogs.com/Simon-X/p/5110328.html

    #include<cstdio>
    int day[294] = {
        0, 1, 5, 4, 1, 4, 5, 5, 6, 0, 4, 6, 0, 6, 6, 0, 2, 0, 1, 6,
        0, 0, 1, 5, 6, 3, 0, 6, 6, 0, 1, 4, 6, 5, 6, 6, 0, 2, 4, 5,
        0, 6, 6, 0, 4, 3, 0, 3, 4, 4, 5, 6, 3, 5, 6, 5, 5, 6, 1, 6,
        0, 5, 6, 6, 0, 4, 5, 2, 6, 5, 5, 6, 0, 3, 5, 4, 5, 5, 6, 1,
        3, 4, 6, 5, 5, 6, 3, 2, 6, 2, 3, 3, 4, 5, 2, 4, 5, 4, 4, 5,
        0, 5, 6, 4, 5, 5, 6, 3, 4, 1, 5, 4, 4, 5, 6, 2, 4, 3, 4, 4,
        5, 0, 2, 3, 5, 4, 4, 5, 2, 1, 5, 1, 2, 2, 3, 4, 1, 3, 4, 3,
        3, 4, 6, 4, 5, 3, 4, 4, 5, 2, 3, 0, 4, 3, 3, 4, 5, 1, 3, 2,
        3, 3, 4, 6, 1, 2, 4, 3, 3, 4, 1, 0, 4, 0, 1, 1, 2, 3, 0, 2,
        3, 2, 2, 3, 5, 3, 4, 2, 3, 3, 4, 1, 2, 6, 3, 2, 2, 3, 4, 0,
        2, 1, 2, 2, 3, 5, 0, 1, 3, 2, 2, 3, 0, 6, 3, 6, 0, 0, 1, 2,
        6, 1, 2, 1, 1, 2, 4, 2, 3, 1, 2, 2, 3, 0, 1, 5, 2, 1, 1, 2,
        3, 6, 1, 0, 1, 1, 2, 4, 6, 0, 2, 1, 1, 2, 6, 5, 2, 5, 6, 6,
        0, 1, 5, 0, 1, 0, 0, 1, 3, 1, 2, 0, 1, 1, 2, 6, 0, 4, 1, 0,
        0, 1, 2, 5, 0, 6, 0, 0, 1, 3, 5, 6, 1, 0
    };
    char opt[7][10] = {
        "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"
    };
    int main(){
        int t, a;
        scanf("%d", &t);
        while (t--){
            scanf("%d", &a);
            puts(opt[day[a % 294]]);
        }
        return 0;
    }
    

    The desire of his soul is the prophecy of his fate
    你灵魂的欲望,是你命运的先知。

  • 相关阅读:
    工序打扎流程(自定义按钮移动、群响应。)
    将FAT磁盘转化为NTFS格式。
    VC监视新硬件插入电脑。
    VC读取分析网络文件
    工序打扎流程(箭头实现、刷新画面)
    VC实现自定义按钮响应拖动
    VC中ListCtrl经验总结【转载】
    C++的优先级
    VC画面闪烁及解决方法
    改变 CListCtrl、CHeaderCtrl 高度、字体、颜色和背景
  • 原文地址:https://www.cnblogs.com/RioTian/p/13849270.html
Copyright © 2020-2023  润新知