#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:
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 | |||||||||||||
| |||||||||||||
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) | |||||||||||||
| |||||||||||||
1) | |||||||||||||
| |||||||||||||
2) | |||||||||||||
| |||||||||||||
3) | |||||||||||||
| |||||||||||||
4) | |||||||||||||
|
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.