UVA, 102 Ecological Bin Packing

Source: Internet
Author: User

Test instructions: Give you three boxes, there are three kinds of bottles in each box B G C, let you classify them, so that there is only one bottle in each box,

Only one bottle can be moved at a time, requiring the minimum number of steps to be moved, the same as the dictionary output

Train of thought: order to get sequence has: BCG BGC CBG CGB GBC GCB Six kinds, all calculate by size to find on the line

PS: The order of input is: B G C, for convenience I sort of b C g

The code is as follows:

1#include <iostream>2#include <cstdio>3 4 using namespacestd;5 intdate[3][3],sum[6];6 intmins,p;7 stringtype[6]={"BCG","BGC","CBG","CGB","GBC","GCB"};8 BOOLDatecin ()//bottle b C G per box9 {Ten     if(SCANF ("%d%d%d%d%d%d%d%d%d", &date[0][0],&date[0][2],&date[0][1],&date[1][0],&date[1][2],&date[1][1],&date[2][0],&date[2][2],&date[2][1])!=EOF) One         return true; A     return false; - } -  the voiddatecal () - { -  -sum[0]=date[1][0]+date[2][0]+ date[0][1]+date[2][1]+ date[0][2]+date[1][2];//BCG +sum[1]=date[1][0]+date[2][0]+ date[0][2]+date[2][2]+ date[0][1]+date[1][1];//BGC -  +sum[2]=date[1][1]+date[2][1]+ date[0][0]+date[2][0]+ date[0][2]+date[1][2];//CBG Asum[3]=date[1][1]+date[2][1]+ date[0][2]+date[2][2]+ date[0][0]+date[1][0];//CGB at  -sum[4]=date[1][2]+date[2][2]+ date[0][0]+date[2][0]+ date[0][1]+date[1][1];//GBC -sum[5]=date[1][2]+date[2][2]+ date[0][1]+date[2][1]+ date[0][0]+date[1][0];//GCB -  -mins=sum[0],p=0; -      for(intI=1;i<6; i++)if(Mins>sum[i]) {mins=sum[i],p=i;} in } -  to voidshowres () + { - datecal (); thecout<<type[p]<<' '<<sum[p]<<Endl; * } $ Panax Notoginseng intMain () - { the      while(Datecin ()) +     { A showres (); the     } +     return 0; -}

UVA, 102 Ecological Bin Packing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.