zoukankan      html  css  js  c++  java
  • HDU7018.Banzhuan(计算几何+贪心)

    思路:

    先考虑最大值,首先,都填满肯定是最大的,但是在填的过程中要怎么最大化代价呢。每次都将要填的物品放到第(n)层,这样由于题意可知他会掉落,但是代价依旧是最大的。
    最大代价如下:
    (n*sum_{x=1}^{n}{x}*sum_{y=1}^{n}{y^{2}}=n*frac{n*(n+1)}{2}*frac{n*(n+1)*(2*n+1)}{6})
    接下来考虑最小值。
    手模一下(n=4)的场景,有以下三种情况:
    (1.)首先在底面平铺一层,然后在左上-右下的对角线上的每个格子都放3个,形成的俯视图如下:
    在这里插入图片描述
    蓝色的数字表示高度,这样的代价为(750)
    (2.)首先在底面平铺一层,然后在右上-左下的对角线上的每个格子都放3个,形成的俯视图如下,代价也是(750):
    在这里插入图片描述
    (3.)
    在这里插入图片描述
    这样的代价为(642).

    假设(t1=frac{n*(n+1)}{2},t2=frac{n*(n+1)*(2*n+1)}{6})
    则答案为(1+(t1-1)*(t2-1)+t1*(t1-1)+t1*(t2-1))
    化简得: (t1*t2+(t1-1)*(t2+t1-2))
    由于涉及到取模,所以计算(t1,t2)时的除法应该用逆元来算。

    代码:

    #pragma GCC optimize(1)
    #pragma GCC optimize(2)
    #pragma GCC optimize(3,"Ofast","inline")
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair<ll, ll>PLL;
    typedef pair<int, int>PII;
    typedef pair<double, double>PDD;
    #define I_int ll
    inline ll read(){ll x = 0, f = 1;char ch = getchar();while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}return x * f;}
    
    inline void write(ll x){if (x < 0) x = ~x + 1, putchar('-');if (x > 9) write(x / 10);putchar(x % 10 + '0');}
    
    #define read read()
    #define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
    #define multiCase int T;cin>>T;for(int t=1;t<=T;t++)
    #define rep(i,a,b) for(int i=(a);i<=(b);i++)
    #define repp(i,a,b) for(int i=(a);i<(b);i++)
    #define per(i,a,b) for(int i=(a);i>=(b);i--)
    #define perr(i,a,b) for(int i=(a);i>(b);i--)
    
    const ll mod=1e9+7;
    ll ksm(ll a, ll b){ll res = 1;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
    
    
    
    int main(){
        int _=read;
        while(_--){
            ll n=read;
            n%=mod;
            ll t1=n*(n+1)%mod;t1=t1*ksm(2,mod-2)%mod;
            ll t2=n*(n+1)%mod;t2=t2*(2*n%mod+1)%mod;t2=t2*ksm(6,mod-2)%mod;
            ll maxx=n*t1%mod*t2%mod;
            maxx=maxx*n%mod;
            ll minn=t1*t2%mod;
            ll tmp=(t1-1+mod)%mod;
            ll tmp1=(t1+t2-2+mod)%mod;
            minn=(minn+tmp*tmp1%mod)%mod;
            printf("%lld
    %lld
    ",minn,maxx);
        }
        
        
        return 0;
    }
    
    
  • 相关阅读:
    sublime text添加snippet
    python __globals__, __file__
    Zen of Python
    Python的魔法函数之
    tornado session
    sqlalchemy学习
    自控力
    无需编译、快速生成 Vue 风格的文档网站
    python描述符理解
    python property理解
  • 原文地址:https://www.cnblogs.com/OvOq/p/15109126.html
Copyright © 2011-2022 走看看