Codeforces Team Olympus (violent)
**************************************** ******************************************************
Original works, from the "Xiaofeng residual month xj" blog, welcome to reprint, reprint please be sure to indicate the source (http://blog.csdn.net/xiaofengcanyuexj ).
For various reasons, there may be many shortcomings. Thank you!
******************************************************* **************************************** **********
A. Team Olympus iadtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
The School has 0 of the capital of Berland hasNChildren studying in it. all the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education ). hence, for each child we know valueTI:
T
I? =? 1, ifI-Th child is good at programming,TI? =? 2, ifI-Th child is good at maths,TI? =? 3, ifI-Th child is good at PEEach child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympus IAS requires teams of three students. the school teachers decided that the teams will be composed of three children that are good at different subjects. that is, each team must have one mathematician, one programmer and one sportsman. of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympus IAD? How shoshould the teams be formed for that?
InputThe first line contains integerN(1? ≤?N? ≤? 5000)-the number of children in the school. The second line containsNIntegersT1 ,?T2 ,?...,?TN(1? ≤?TI? ≤? 3), whereTIDescribes the skill ofI-Th child.
OutputIn the first line output integerW-The largest possible number of teams.
Then printWLines, containing three numbers in each line. each triple represents the indexes of the children forming the team. you can print both the teams, and the numbers in the triplets in any order. the children are numbered from 1NIn the order of their appearance in the input. Each child must particle in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with valueWEqual to 0.
Sample test (s) Input71 3 1 3 2 1 2
Output23 5 26 7 4
Input42 1 1 2
Output0
Question:
This question requires that 1, 2, 3 be evenly allocated to three containers as much as possible to ensure that each container contains 1, 2, and 3. Find the maximum number of combinations and output a possible combination. Brute force enumeration is supported! The time complexity is O (n), and the space complexity is O (n ).
Source code:
#include
#include
using namespace std;const int MAXN=5000+100;int per[3][MAXN];int min(int a,int b){return a