USACO [19-20] Dec silver component explanations

1 MooBuzz

This problem is actually a math problem.

We first look to meet the requirements of number: 1,2,4,7,8,11,13,14 ......

Beyond that we found after looking for is a 15k increase in the number 8 as this: 16 ...... 19 ...... 29 ......

Find the law found k = n / 8

year = 15 * n / 8 + a [n% 8] (a [] = {} 14,1,2,4,7,8,11,13)

But we found errors when n is a multiple of eight, especially when it sentenced n% 8 == 0 ans = 15 * n / 8-1 to

#include <iostream>
#include <cstdio>
using namespace std;
int n, d;
int a[8] = {14, 1, 2, 4, 7, 8, 11, 13};
int main() {
    freopen("moobuzz.in", "r", stdin);
    freopen("moobuzz.out", "w", stdout);
    cin >> n;
    d = n / 8;
    if (n % 8) {
        cout << d * 15 + a[n % 8];
    } else {
        cout << d * 15 - 1;
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}

 Ing continuously updated

Guess you like

Origin www.cnblogs.com/zcr-blog/p/12040605.html