zoukankan      html  css  js  c++  java
  • P1679 神奇的四次方数

    P1679 神奇的四次方数
    用一些什么东西组成一个什么东西,要求什么东西最优,这时候要考虑背包,不过要分析清楚是什么类型的背包。
    这题显然是个完全背包。

    #include<iostream>
    #include<cstdio>
    #include<queue>
    #include<algorithm>
    #include<cmath>
    #include<ctime>
    #include<cstring>
    #define inf 2147483646
    #define For(i,a,b) for(register long long i=a;i<=b;i++)
    #define p(a) putchar(a)
    #define g() getchar()
    //by war
    //2017.10.16
    using namespace std;
    long long n;
    long long f[100010];
    long long w[20];
    void in(long long &x)
    {
        long long y=1;
        char c=g();x=0;
        while(c<'0'||c>'9')
        {
        if(c=='-')
        y=-1;
        c=g();
        }
        while(c<='9'&&c>='0')x=x*10+c-'0',c=g();
        x*=y;
    }
    void o(long long x)
    {
        if(x<0)
        {
            p('-');
            x=-x;
        }
        if(x>9)o(x/10);
        p(x%10+'0');
    }
    
    long long POW(long long a,long long b)
    {
        while(b%2==0)
        {
            a*=a;
            b>>=1;
        }
        long long r=1;
        while(b>0)
        {
            if(b%2==1)
            r*=a;
            a*=a;
            b>>=1;
        }
        return r;
    }
    
    int main()
    {
        in(n);
        long long cnt;
        for(cnt=1;POW(cnt,4)<=n;cnt++)
        {
            w[cnt]=POW(cnt,4);
        }
        For(i,1,n)
        f[i]=inf;
        f[0]=0;
        For(i,1,cnt)
         For(j,w[i],n) 
           f[j]=min(f[j],f[j-w[i]]+1);
        o(f[n]);
         return 0;
    }
  • 相关阅读:
    Python3 学习第八弹: 模块学习一之模块变量
    Python3 学习第六弹: 迭代器与生成器
    Python3 学习第五弹:类与面向对象
    Java之泛型
    Java之工具类Collections
    Java之map
    Java集合之List
    Java集合之TreeSet
    Java集合
    Java异常处理
  • 原文地址:https://www.cnblogs.com/war1111/p/7678633.html
Copyright © 2011-2022 走看看