魔方系列——最小装箱

来源:互联网 发布:dw如何连接动态数据 编辑:程序博客网 时间:2024/05/20 10:13

魔方系列——最小装箱
Time Limit: 1000msMemory Limit: 65536KB 64-bit integer IO format: %lld Java class name: Main
Prev Submit Status Statistics Discuss Next
DreamFox为了发展地大的魔方水平,经常会到世界盲拧记录保持者瓦西里处去进货一些魔方。进货的魔方一共有6种,分别是1*1, 2*2, 3*3, 4*4, 5*5, 6*6.(当然魔方是立体的,但为了问题简化我们就只看平面吧,即假设所有魔方的高度和箱子一样高)。而且瓦西里前辈为了减少麻烦,只提供一种6*6大小的箱子。就是无论你买多少魔方,全部都得装到这种6*6的箱子里。
现在问题来了,DreamFox发现,如果有效的放置魔方的位置,就可以使需要的箱子尽可能的少。但是如何让箱子最少呢?DreamFox这个人比较懒,所以请你编写一个程序计算需要箱子的最小值。

Input
第1行:N,有N组数据(N < 300)。
第2..N+1行:有6个数,分别代表1*1, 2*2, 3*3, 4*4, 5*5, 6*6的魔方的个数。

Output
N行:每组数据的最小箱子数。

Sample Input
2
0 0 4 0 0 1
7 5 1 0 0 0

Sample Output
2
1

Source
中国地质大学(北京)第三届程序设计竞赛

相当于6x6的方格内放入1x1,2x2,3x3,4x4,5x5,6x6 的卡片的个数:
6x6直接铺满;5x5最多放一个,剩下的用1x1的铺;4x4最多放一个,剩下的能最多放下5个2x2和7个1x1;3x3的要特判是不是4的倍数,然后用2x2的、1x1的分别判断;最后就是分别判断2x2和1x1的。

繁杂但是比较好理解的代码如下:

#include<stdio.h>int main(){    int t,a,b,c,d,e,f;    scanf("%d",&t);    while(t--)    {        scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);        if(a==0&&b==0&&c==0&&d==0&&e==0&&f==0)            break;        int sum=0,s;        sum+=f;        if(e>0)        {            sum+=e;            if(a>0)                a-=e*11;        }        if(d>0)        {            sum+=d;            b-=d*5;            if(b<0)                a+=b*4;        }        if(c%4!=0)        {            sum+=1+c/4;            c%=4;             if(c==3)            {                if(b>0)                {                    b-=1;                    a-=5;                }                else                    a-=9;            }            else if(c==2)            {                if(b>0)                {                    a-=6;                    b-=3;                }                else                {                    a-=18;                }            }            else if(c==1)            {                if(b>0)                {                    b-=5;                    a-=7;                }                else                {                    s= 27;                    a-=s;                }            }        }        else            sum+=c/4;        if(b>0)        {            if(b%9!=0)            {                sum+=b/9+1;                b%=9;                a-=36-b*4;            }            else                sum+=b/9;        }        if(a>0)        {            sum+=a/36;            if(a%36!=0)                sum+=1;        }        printf("%d\n",sum);    }    return 0;}

这个是某个学长写的,具体的话,我也不是很懂,存下来先,以后有时间还是要再回来回顾回顾。

#include <stdio.h>#include <algorithm>#include <math.h>#include <string.h>#include <iostream>#include <queue>using namespace std;int n,m;int dx[5];int dy[5];int main(){    int a[7];    int n,m;    scanf("%d",&n);    while(n--)    {        for(int i=1; i<=6; ++i) scanf("%d",&a[i]);        int ans,t1,t2;        ans= a[6]+a[5]+a[4]+(a[3]+3)/4;        t2=a[4]*5+(a[3]%4==0?0:7-(a[3]%4*2));        if(a[2]>t2) ans+=(a[2]-t2+8)/9;        t1=ans*36-a[6]*36-a[5]*25-a[4]*16-a[3]*9-a[2]*4;        if(a[1]>t1) ans+=(a[1]-t1+35)/36;        printf("%d\n",ans);    }    return 0;}
0 0
原创粉丝点击