POJ 1017 Packets

题目链接:http://poj.org/problem?id=1017

题目描述:

    给定6个数,表示是1*12*2....6*6的正方形的个数,现将这些正方形放在6*6的正方形中,问最少需要多少个6*6的正方形。

    纯模拟即可解。由大到小考虑即可。

#include<cstdio>
#include<iostream>
using namespace std ;

int a[6] ;

void cal(){
	int res = 0 ;
	int num1, num2 ;
	//6
	res += a[5] ;
	//5
	res += a[4] ;
	num1 = a[4]*11 ;
	//4
	res += a[3] ;
	num2 = 5*a[3] ;
	//3
	if( a[2] % 4 == 0 ){
		res += a[2] / 4 ;	
	} 
	else{
		res += a[2] / 4 + 1 ;
		switch(a[2]%4){
			case 1 :
				num2 += 5 ;
				num1 += 7 ;
				break ;
			case 2:
				num2 += 3 ;
				num1 += 6 ;
				break ;
			case 3:
				num2 += 1 ;
				num1 += 5 ;
				break ;
		}
	}
	//2
	if( num2 >= a[1] ){
		num2 -= a[1] ;
		num1 += num2*4 ;
	} 
	else{
		a[1] -= num2 ;
		if( a[1] % 9 == 0 ){
			res += a[1] / 9 ;	
		}
		else{
			res += a[1] / 9 + 1 ;
			num1 += (9-a[1]%9)*4 ;	
		}
	}
	//1
	if( num1 < a[0]){
		a[0] -= num1 ;
		if( a[0] % 36 == 0 ){
			res += a[0] / 36 ;	
		}
		else{
			res += a[0] / 36 + 1 ;			
		}
	}
	cout << res << endl ;	
}
int main(){
	freopen("1234.in","r",stdin) ;
	while( 1 ){
		int num = 0 ;
		for( int i = 0; i < 6; i++ ){
			scanf("%d",&a[i]) ;
			if( a[i] == 0 )
				num++ ;
		}
		if( num == 6 ) break ;
		cal() ;
	}
	return 0 ;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值