zoukankan      html  css  js  c++  java
  • CF--思维练习--CodeForces

    ACM思维题训练集合
    A new Berland businessman Vitaly is going to open a household appliances’ store. All he’s got to do now is to hire the staff.

    The store will work seven days a week, but not around the clock. Every day at least k people must work in the store.

    Berland has a law that determines the order of working days and non-working days. Namely, each employee must work for exactly n consecutive days, then rest for exactly m days, then work for n more days and rest for m more, and so on. Vitaly doesn’t want to break the law. Fortunately, there is a loophole: the law comes into force on the day when the employee is hired. For example, if an employee is hired on day x, then he should work on days [x, x + 1, …, x + n - 1], [x + m + n, x + m + n + 1, …, x + m + 2n - 1], and so on. Day x can be chosen arbitrarily by Vitaly.

    There is one more thing: the key to the store. Berland law prohibits making copies of keys, so there is only one key. Vitaly is planning to entrust the key to the store employees. At the same time on each day the key must be with an employee who works that day — otherwise on this day no one can get inside the store. During the day the key holder can give the key to another employee, if he also works that day. The key will handed to the first hired employee at his first working day.

    Each employee has to be paid salary. Therefore, Vitaly wants to hire as few employees as possible provided that the store can operate normally on each day from 1 to infinity. In other words, on each day with index from 1 to infinity, the store must have at least k working employees, and one of the working employees should have the key to the store.

    Help Vitaly and determine the minimum required number of employees, as well as days on which they should be hired.

    Input
    The first line contains three integers n, m and k (1 ≤ m ≤ n ≤ 1000, n ≠ 1, 1 ≤ k ≤ 1000).

    Output
    In the first line print a single integer z — the minimum required number of employees.

    In the second line print z positive integers, separated by spaces: the i-th integer ai (1 ≤ ai ≤ 104) should represent the number of the day, on which Vitaly should hire the i-th employee.

    If there are multiple answers, print any of them.

    Examples
    Input
    4 3 2
    Output
    4
    1 1 4 5
    Input
    3 3 1
    Output
    3
    1 3 5
    Sponsor
    **这个题之前做过,今天写了1个半小时才写出来,思维真的是不行了。**还是不能落下训练,。
    在这里插入图片描述
    发现直接模拟就能过,想搞点简单wa了N多遍。
    思路就是第一天肯定是K个人,直接模拟那K个人休息的M天,让其也保持K人就行,一定要注意第m天结束时一定要有人把钥匙送回第一拨人手上。

    #include <bits/stdc++.h>
    using namespace std;
    int a[10000];
    int ans[10000];
    int main()
    {
        int n, m, k;
        cin >> n >> m >> k;
        if (m <= n - 2)
        {
            cout << 2 * k << endl;
            for (int i = 0; i < k; i++)
                printf("1 ");
            printf("%d ", n);
            n++;
            for (int i = 1; i < k; i++)
                printf("%d ", n);
            puts("");
        }
        else
        {
            int cnt = k + 1;
    
            for (int i = 1; i <= m; i++)
            {
                if (a[i] == k)
                    continue;
                if (a[i] == 0)
                {
                    ans[cnt++] = i - 1;
                    for (int j = 0; j < n - 1; j++)
                        a[i + j]++;
                }
    
                int w = k - a[i];
                for (int j = 0; j < n; j++)
                    a[i + j] += w;
                for (int j = 0; j < w; j++)
    
                    ans[cnt++] = i;
            }
            if (a[m + 1] == 0)
                ans[cnt++] = m;
            cout << cnt - 1 << endl;
            for (int i = 0; i < k; i++)
                printf("1 ");
            for (int i = k + 1; i < cnt; i++)
                printf("%d ", ans[i] + n);
            puts("");
        }
    }
    
    
  • 相关阅读:
    Layui 两个table 人员选择 多选
    iphone7 忘记密码 重装系统
    使用hql-统计连续登陆的三天及以上的用户
    azkaban群起/群停脚本
    Hive读取索引文件问题:select * 和select count(*)读取出来的行数不一致
    scala/java等其他语言从CSV文件中读取数据,使用逗号','分割可能会出现的问题
    hadoop3.1.3版本的secondaryNamenode的web界面不能显示的问题?
    启动kafka消费报错:WARN [Consumer clientId…] 1 partitions have leader brokers without a matching listener,…
    centos6和centos7的防火墙命令,以及它们的区别是是什么?
    kafka项目经验之如何进行Kafka压力测试、如何计算Kafka分区数、如何确定Kaftka集群机器数量
  • 原文地址:https://www.cnblogs.com/lunatic-talent/p/12798425.html
Copyright © 2011-2022 走看看