SRM 387 DIV2 [600]
来源:互联网 发布:linux安装控制面板 编辑:程序博客网 时间:2024/04/29 20:33
#include<string>
#include<vector>
using namespace std;
class MarblesRegroupingEasy
...{
public:
int minMoves(vector<string> boxes)
...{
int res,len;
res=boxes.size()-1;
len=boxes[0].size();
int flag[50]=...{0};
for (int i=0;i!=boxes.size();++i)...{
int pos=0,num=0;
for (int j=0;j!=len;++j)
if (boxes[i][j]!='0')...{
++num;
pos=j;
}
if (num==0) --res;
if (num==1&& flag[pos]==0)...{
--res;
flag[pos]=1;
}
}
return res;
}
};
Problem Statement
John is a marble collector. He keeps his marbles in boxes. He also likes to keep things in order.
One day, his younger brother was playing with the marbles. After he was done, he put all the marbles back in boxes, but he did it randomly, so certain boxes might now contain marbles of different colors. John wants him to regroup the marbles so that the grouping satisfies the following restrictions:
- At most one box, called the joker box, may contain marbles of different colors. We can choose any box as a joker box.
- Every box except the joker box must either be empty or only contain marbles of the same color.
- All marbles of the same color, except those in the joker box, must be in the same box. It's possible that all marbles of the same color are in the joker box.
You are given a vector <string> boxes, where the j-th digit of the i-th element is the number of marbles of color j in the i-th box. Return the minimal number of moves necessary to regroup the marbles, where each move consists of taking any number of marbles from one box (not necessarily of the same color) and putting them into another.
Definition
Class: MarblesRegroupingEasy Method: minMoves Parameters: vector <string> Returns: int Method signature: int minMoves(vector <string> boxes) (be sure your method is public)Constraints
- boxes will contain between 1 and 50 elements, inclusive. - Each element of boxes will contain between 1 and 50 characters, inclusive. - All elements of boxes will contain the same number of characters. - Each element of boxes will contain only digits ('0'-'9').Examples
0){"20", "11"}
Returns: 0Let box 1 be the joker box. All marbles of color 0, except those in the joker box, are in box 0. Box 0 contain only marbles of the color 0. So, all restrictions are already satisfied. 1)
{"11", "11", "10"}
Returns: 1There are several possible solutions:
- Move all marbles from box 0 into box 1. Box 1 is the joker box.
- Move all marbles from box 1 into box 0. Box 0 is the joker box.
- Move the marble of color 0 from box 0 into box 1 or 2. Box 1 is the joker box.
- Move the marble of color 0 from box 1 into box 0 or 2. Box 0 is the joker box.
{"10", "10", "01", "01"}
Returns: 1Let box 0 be the joker box. Now we only need to group all marbles of color 1 into one box. 3)
{"11", "11", "11", "10", "10", "01"}
Returns: 34)
{"020008000070", "000004000000", "060000600000", "006000000362", "000720000000", "000040000000", "004009003000", "000800000000", "020030003000", "000500200000", "000000300000"}
Returns: 6
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
- SRM 387 DIV2 [600]
- SRM 387 DIV2 [250]
- SRM 600 DIV2
- topcoder srm 531 div2 600pt
- SRM 531 div1 600/300 div2 950
- SRM 114 DIV2 [550]
- SRM 398 DIV2 [250]
- SRM 399 DIV2 [250]
- SRM 397 DIV2 [500]
- SRM 400 DIV2 [250]
- SRM 400 DIV2 [500]
- SRM 397 DIV2 [1000]
- SRM 405 DIV2
- SRM 421Div2 500
- SRM 457 Div2 500
- SRM 465(DIV1 DIV2)
- SRM 465(DIV1 DIV2)
- SRM 481 div2
- insmod module 失败(skyeye + armlinux)
- 如何通过崩溃地址找到出错的代码行(ZT)
- 封装机制封装的概念
- 收藏几段SQL语句和存储过程
- 成员方法
- SRM 387 DIV2 [600]
- C++网络开发包ACE环境的配置与调试
- 第5章 消息、继承与多态1
- SQL交叉表实例
- 抽象类、接口与包
- CString,string,char*的综合比较(一)
- 用DTS导入文件的两个小技巧
- HttpService简单应用
- CString,string,char*的综合比较(二)