POJ 1017 Packets

来源:互联网 发布:有毒网络剧有第二季吗 编辑:程序博客网 时间:2024/06/05 03:12

题目链接: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 ;//6res += a[5] ;//5res += a[4] ;num1 = a[4]*11 ;//4res += a[3] ;num2 = 5*a[3] ;//3if( 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 ;}}//2if( 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 ;}}//1if( 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 ;}

0 0
原创粉丝点击