[Offer收割]编程练习赛12 register

Ended

Participants:1323

Verdict:Accepted
Score:100 / 100
Submitted:2017-04-02 12:43:02

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <cstring>
using namespace std;
const int MAX = 1000000;
int cost[MAX] = { 0 };
inline int min(int a, int b) {
    return a < b ? a : b;
}
int main()
{
    int total_width;
    memset(cost, 0, sizeof(int)*MAX);
    int N;
    cin >> N;
    for (int n = 0; n < N; n++) {  // layer
        total_width = 0;
        int M;
        int curr = 0;
        cin >> M;
        for (int m = 0; m < M; m++) {  // each brick
            int width;
            cin >> width;
            total_width += width;
            for (int w = 0; w < width-1; w++) { // compute cost
                cost[curr++] += 1;
            }
            curr++;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX