您的位置:首页 > 其它

POJ 1017 Packets

2014-10-16 16:41 351 查看
题目链接:http://poj.org/problem?id=1017

题目描述:

    给定6个数,表示是1*1,2*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 ;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  poj 模拟