贪心算法

POJ - 1017 好题强烈推荐 2*2的放置方法我想了半天 妙啊 看了他人的题解 明白了

题解:https://www.cnblogs.com/mycapple/archive/2012/08/23/2652070.html

#include<iostream>
#include<cstdio>
#include<cstring>
#define Max 100000
using namespace std;
int n,s;
int c[Max],y[Max];
long long sum=0;
int ways[]={0,5,3,1};
int c2;//能放2*2的数 
int main()
{
int s1,s2,s3,s4,s5,s6;
int total=0;
int temp2=0;//2*2的盒子 
int temp1=0;//1*1的空间 
while(1){
cin>>s1>>s2>>s3>>s4>>s5>>s6;
if(s1==0&&s2==0&&s3==0&&s4==0&&s5==0&&s6==0) break;
total=s6+s5+s4+(s3+3)/4;//6,5,4只能直接放 3要向上调整 
temp2=5*s4+ways[s3%4];//2*2的数量(已经放置) 
if(s2>temp2)//如果还没放完
{
total+=(s2-temp2+8)/9;//向上取整 
}
//计算1*1能怎么放 
temp1=total*36-s6*36-s5*25-s4*16-s3*9-s2*4;
if(s1>temp1)
{
total+=(s1-temp1+35)/36;
}
cout<<total<<endl;  
}
return 0;
}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值