第十二届蓝桥杯c/c++组--D 货物摆放

方法一:
将n一分为二(n=a乘以b)再将a一分为二(a=c乘以d)

#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
#define ll long long
ll n=2021041820210418;
struct v{
    ll a,b,c;
    bool operator<(const v&y)const{
        if(y.a==a){
            if(b==y.b){
                return y.c<c;
            }
            return y.b<b;
        }
        return y.a<a;
    }
} ;
int main()
{
    int t=0;
    ll num[10000];
    set<v>s;
    for(int i=1;i<=n/i;i++){
        if(n%i==0){
           num[t++]=i;
           num[t++]=n/i;
        }
    }
    for(int i=0;i<t;i++){
        for(ll j=1;j<=num[i]/j;j++){
            if(num[i]%j==0){
                ll  a=j,b=num[i]/j,c=n/num[i],t;
                s.insert({a,b,c});
                s.insert({b,a,c});
            }
        }
    }
    cout<<s.size();
    return 0;
}

方法二:
求出n所有的质因数

#define ll long long
ll n = 2021041820210418;
ll a[102], cnt;
struct Node {
    ll l, w, h;
    Node() {}
    Node(ll _l, ll _w, ll _h) : l(_l), w(_w), h(_h) {}
    bool operator<(const Node &y) const {
        if (l == y.l) {
            if (w == y.w) {
                return h < y.h;
            }
            return w < y.w;
        }
        return l < y.l;
    }
};
set<Node> ans;
void dfs(int p, ll l, ll w, ll h) {
    if (p == cnt) {
        ans.insert(Node(l, w, h));
        return;
    }
    dfs(p + 1, l * a[p], w, h);
    dfs(p + 1, l, w * a[p], h);
    dfs(p + 1, l, w, h * a[p]);
}
int main() {
    for (ll i = 2; i * i <= n; ++i) {
        if (n % i == 0) {
            a[cnt++] = i;
            n /= i;
            i--;
        }
    }
    a[cnt++] = n;
    dfs(0, 1, 1, 1);
    cout << ans.size() << endl;
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值