程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> Codeforces Team Olympiad(暴力)

Codeforces Team Olympiad(暴力)

編輯:C++入門知識

Codeforces Team Olympiad(暴力)


***********************************************聲明******************************************************

原創作品,出自 “曉風殘月xj” 博客,歡迎轉載,轉載時請務必注明出處(http://blog.csdn.net/xiaofengcanyuexj)。

由於各種原因,可能存在諸多不足,歡迎斧正!

*********************************************************************************************************

A. Team Olympiad time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output

The School №0 of the capital of Berland has n children 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 value ti:

ti?=?1, if the i-th child is good at programming, ti?=?2, if the i-th child is good at maths, ti?=?3, if the i-th child is good at PE

Each child happens to be good at exactly one of these three subjects.

The Team Scientific Decathlon Olympias 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 Olympiad? How should the teams be formed for that?

Input

The first line contains integer n (1?≤?n?≤?5000) — the number of children in the school. The second line contains n integers t1,?t2,?...,?tn (1?≤?ti?≤?3), where ti describes the skill of the i-th child.

Output

In the first line output integer w — the largest possible number of teams.

Then print w lines, 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 1 to n in the order of their appearance in the input. Each child must participate 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 value w equal to 0.

Sample test(s) Input
7
1 3 1 3 2 1 2
Output
2
3 5 2
6 7 4
Input
4
2 1 1 2
Output
0

題解:

本題要求把1,2,3盡可能的平均分配到3個容器中,保證每一個都包含1、2、3,求這樣的最大組合數以及輸出一種可能的組合。可以暴力枚舉!時間復雜度O(n),空間復雜度也為O(n)。

源代碼:

#include
#include
using namespace std;

const int MAXN=5000+100;
int per[3][MAXN];

int min(int a,int b)
{
	return a




  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved