SRM 387 DIV2 [600]
2008-04-27 19:32
573 查看
#include<iostream>
#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 | ||||||||||||
| ||||||||||||
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) | ||||||||||||
|
相关文章推荐
- SRM 600 DIV2
- SRM 668 DIV 2 IsItASquare 600-point
- topcoder srm 600 div1
- SRM 531 div1 600/300 div2 950
- SRM549 Div1 600
- SRM 387 DIV2 [250]
- SRM 600 DIV1
- SRM 452 DIV 1 总结
- TopCoder SRM 474 DIV1 1000
- TopCoder SRM 588 DIV2 KeyDungeonDiv2
- srm 654 div2 1000 (DP,最大连续和拓展, 有亮点)
- SRM 590 DIV1
- topcoder SRM 654 DIV2 1000 SuccessiveSubtraction2 题解(dp)
- Topcoder SRM 656 DIV2 1000 题解(动态规划)
- TC SRM 593 DIV1 250(dfs)
- srm 181 div1 1000(状压dp)
- topcoder SRM 594 DIV2 AstronomicalRecordsEasy
- srm 152 div1 500(简单概率计算)
- TopCoder SRM 659 Div2 Problem 500 - PublicTransit (思维)
- TopCoder算法竞赛题2:SRM 146 DIV 2, 250-point