计蒜客比赛 - 2018 计蒜之道 初赛 第五场 A B 题解

<A> 链接:https://nanti.jisuanke.com/t/27292

思路:

由于所有的箱子可以看成哟一个大的立方体,所有前后左右上这五个朝向各去掉一层以后,仍为立方体,那么你现在知道的是剩下多少的箱子,换句话说,已知条件是,被在五个朝向各去掉一层后的立方体的体积,那么要求原来立方体最大最小的体积分别是多少应该怎么操作呢,我的思路是,挨个枚举出来就好了,把原来的体积 V 拆成 i * j * k,即立方体长宽高,那么就要考虑除底面外,各个面摘除1层的手段了,上面去掉一层,那新的高就是原来的高减一,前后左右各去掉一层之后,新的长和宽都变为原来的值减2了,所以就看枚举出来的长 i,  宽 j , 高 k , 取多少能让体积最大或最小就好了。

本人AC代码:

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int Inf = 1e9 + 7;

int main() {
    int cas;
    cin >> cas;
    int p;
    int r1, r2;
    while(cas--) {
        cin >> p;
        int r1 = Inf;
        int r2 = 0;
        for(int i = 1; i <= 1000; i++) {
            if(p % i == 0) {
                for(int j = 1; j <= 1000; j++) {
                    if(p % (i * j) == 0) {
                        int k = p / (i * j);
                        int tmp = (k + 1) * (i + 2) * (j + 2);
                        r1 = min(r1, tmp); r2 = max(r2, tmp);
                        tmp = (k + 2) * (i + 1) * (j + 2);
                        r1 = min(r1, tmp); r2 = max(r2, tmp);
                        tmp = (k + 2) * (i + 2) * (j + 1);
                        r1 = min(r1, tmp); r2 = max(r2, tmp);
                    }
                }
            }
        }
        r1 -= p;
        r2 -= p;
        cout << r1 << " " << r2 <<endl;
    }

}


<B> 链接:https://nanti.jisuanke.com/t/27289

思路:

这题,大暴力就OK,n方枚举一下满足条件的即可,对每次枚举出来的两个数,进行模十除十操作就行,如果是3位数那就取三次模10的值相乘,两位数就取前两次,一位数就取第一次即可,然后再取gcd看满足题意与否。给的区间是1 ~ 1000,1000能取到,为什么只最高只需要看三位数就行呢,因为题意要求取gcd的两个数均不能为0,f(1000) = 1*0*0*0 = 0,显然不满足题意,故不必考虑。

本人AC代码:

扫描二维码关注公众号,回复: 1945633 查看本文章

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int mod = 998244353;

int gcd(int a, int b) {
    return (a == 0) ? b : gcd(b % a, a);
}

int main() {
    int n;
    ll k;
    cin >> n >> k;
    int cnt = 0;
    int p1, p2, s, t;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            s = i;
            t = j;

            int a = s % 10;
            s /= 10;
            int b = s % 10;
            s /= 10;
            int c = s % 10;

            int A = t % 10;
            t /= 10;
            int B = t % 10;
            t /= 10;
            int C = t % 10;

            if(i >= 100) p1 = a * b * c;
            else if(i >= 10 && i < 100) p1 = a * b;
            else p1 = a;
            if(j >= 100) p2 = A * B * C;
            else if(j >= 10 && j < 100) p2 = A * B;
            else p2 = A;
            if(p1 * p2 > 0 && gcd(p1, p2) <= k && gcd(p1, p2) > 0) {
                cnt++;
                if(cnt >= mod) cnt %= mod;
            }
        }
    }
    cout << cnt << endl;
}

猜你喜欢

转载自blog.csdn.net/ericgipsy/article/details/80470312