UVA 102 Ecological bin packaging

6 篇文章 0 订阅
5 篇文章 0 订阅



题目的意思是给你三个箱子,1号,2号,3号

每个箱子装了三种颜色的瓶子(假设为球,便于记忆)其中颜色分别为brown,green, clear;

比如:1 2 3 4 5 6 7 8 9

就意味着:

1号               2号                    3号

B     G  C    B   G   C       B   G  C

1    2    3     4   5    6      7    8    9

做法就是你要让移动次数最少,多种方案时按照字母顺序求解输出

无论你怎么移动最优的算法中有一种颜色是不会移动的,让这三个箱子不动的部分的和最大时,就是移动的部分最少的情况. /* Name: uva 102 ebp-ac Copyright: angieeve Author: zj Date: 07-04-13 13:01 Description: greedy */ #include <iostream> #include <cstdlib> #include <algorithm> #include <cstring> #include <cstdio> using namespace std; #define num 9 #define way 6 #define max 11 #define inf 0xffffff int data[max]; struct ways{ int a,b,c; string color; }ways[]={ {1,5,9,"BGC"},{1,8,6,"BCG"},{4,2,9,"GBC"}, {4,8,3,"CBG"},{7,2,6,"GCB"},{7,5,3,"CGB"} }; int main(){ int maxv,count,sum; string str; while(scanf("%d",&data[1])!=EOF){ maxv=-inf; count=data[1]; for(int i=2;i<=num;i++){ scanf("%d",&data[i]); count+=data[i]; } //count 用来存放所有的bottle的总数 //for(int i=1;i<=num;i++) cout<<"datai="<<data[i]<<endl; //data[i]存放输入数据 for(int i=0;i<way;i++){ sum=data[ways[i].a]+data[ways[i].b]+data[ways[i].c]; // //cout<<"sum"<<sum<<endl;sum是用来求解每种方式下的所移动的步数 // if(maxv<sum){maxv=sum;str=ways[i].color;} else if (maxv==sum&&str>ways[i].color) str=ways[i].color; //cout<<maxv<<"maxv"<<endl;maxv更新最多的步数 // cout<<count<<"count"<<endl; } cout<<str<<' '<<count-maxv<<endl; } return 0; }



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值