• C++-POJ1017-Packets


    贪心算法,思路见代码

    本来想搜索,结果有O(1)的算法,我佛了

    其实每一种6x6的方案可以打表预处理,然后dp or search

    但是既然可以贪心何乐而不为呢?

     1 #include <set>
     2 #include <map>
     3 #include <cmath>
     4 #include <queue>
     5 #include <vector>
     6 #include <cstdio>
     7 #include <cstdlib>
     8 #include <cstring>
     9 #include <iostream>
    10 #include <algorithm>
    11 using namespace std;
    12 /*
    13 //体积为4,5,6的有一个就需要一个箱子,体积为3的需要(c+3)/4个箱子
    14 //剩余的空间我们采取贪心的策略,先放2x2的箱子,4x4的箱子还剩下boxD*5个2x2的空间
    15 //对于3x3底面积的需要分情况讨论
    16 //3x3的箱子装完了还剩下3个,留下了1个2x2的空间
    17 //3x3的箱子装完了还剩下2个,留下了3个2x2的空间
    18 //3x3的箱子装完了还剩下2个,留下了5个2x2的空间
    19 //解决了2x2的空间还剩下1x1的,总体积减去所有其他箱子的体积,就剩下1x1的空间了。
    20 */
    21 int main() {
    22     for(int a,b,c,d,e,f,ans; scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f)&&(a+b+c+d+e+f);) {
    23         ans=(c+3)/4+d+e+f;
    24         int left2x2=d*5;
    25         if(c%4==1)left2x2+=5;
    26         else if(c%4==2)left2x2+=3;
    27         else if(c%4==3)left2x2++;
    28         if(b>left2x2)ans+=((b-left2x2)+8)/9;
    29         int left1x1=36*ans-4*b-9*c-16*d-25*e-36*f;
    30         if(a>left1x1)ans+=((a-left1x1)+35)/36;
    31         cout<<ans<<endl;
    32     }
    33     return 0;
    34 }
    ~~Jason_liu O(∩_∩)O
  • 相关阅读:
    springboot系列六、springboot配置错误页面及全局异常
    一行代码完成 Java的 Excel 读写--easyexcel
    Docker搭建Portainer可视化界面
    使用spring-boot-admin对spring-boot服务进行监控
    SpringBoot集成JWT实现权限认证
    安装Docker
    Java的 Excel 读写--easyexcel
    SpringBoot 配置文件提示功能
    Mysql数据库中获取时间
    javascript-观察者模式
  • 原文地址:https://www.cnblogs.com/JasonCow/p/12268745.html
Copyright © 2020-2023  润新知