ZOJ1200 Mining【水题】

Mining
Time Limit: 2 Seconds Memory Limit: 65536 KB
     A mining base needs to build some robots to collect at least 10000 units of resource. Each robot will start from the base, reach the diggings in S minutes, work for W minutes, and then take C units of resource back to the base in S minutes.
     To speed up this procedure, K robots will be built at the base. It takes M minutes to produce one robot. A robot will be set to start working immediately after it is built, and producing the next robot will be on line right after. This procedure continues untill all the robots are built.
     Due to the limitation of the mining equipments, there can be only one robot digging at the working area. That is, it is only after the currently working robot finishes its collecting work and starts getting back to the base that the next robot can work at the diggings.
     Now it is your job to write a program to simulate this procedure, and find out how many minutes it will take to collect at least 10000 units of resource.

Input
There are several lines of input. Each line contains a test case which consists of 5 integers, namely S, W, C, K, and M.

Output
For each test case, you are asked to output an integer t, which is the number of minutes taken to collect at least 10000 units of resource.

Sample Input:
10 20 10 1 5

Sample Output:
40005

Source: Zhejiang University Local Contest 2002, Preliminary

问题链接:ZOJ1200 Mining
问题简述:(略)
问题分析
    制作K个机器人,制作每个机器人需要M分钟,每个机器人需要S分钟走到工作现场,工作W分钟,带回来C单位资源,回来时间也需要S分钟。计算收集至少10000单元个资源需要多少分钟。
    采用模拟计算即可,需要注意向上取整的计算公式。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C语言程序如下:

/* ZOJ1200 Mining */

#include 

#define N 10000
int wt[N];

int main(void)
{
    int s, w, c, k, m, i, j;
    while(scanf("%d%d%d%d%d", &s, &w, &c, &k, &m) != EOF) {
        int cnt = (10000 + (c - 1)) / c;        /* 机器人搬运次数,向上取整 */
        if(cnt < k) k = cnt;
        for(i = 1; i <= k; i++)
            wt[i] = m * i + s;

        int cur = 0;
        for(i = 1; i <= cnt; i++) {
            if(cur < wt[1]) cur = wt[1];
            cur += w;
            int rt = cur + 2 * s;
            j = 1;
            int child = j * 2;
            while(child <= k) {
                if(child + 1 <= k && wt[child + 1] < wt[child])     /* 右孩子小 */
                    child++;
                if(rt  > wt[child]) {
                    wt[j] = wt[child];
                    j = child;
                    child *= 2;
                } else
                    break;
            }
            wt[j] = rt;
        }
        printf("%d\n", cur + s);
    }

    return 0;
}

你可能感兴趣的:(#,ICPC-备用二,#,ICPC-水题题解三,#,ICPC-ZOJ,ACM考试与比赛)