Codeforces Round #279 (Div. 2) A. Team Olympiad

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

题意:给你n个数字,每个数字都是1-3中的一个,让你求能组成1,2,3的组数,并输出相应的组员序列。

做法:直接做。

#include <iostream>
#include <cstdio>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <algorithm>
#include<ctime>
#define esp 1e-6
#define LL long long
#define inf 0x0f0f0f0f
using namespace std;
int main()
{
    vector<int>pp[10];
    int n,i,num[50005];
    while(scanf("%d",&n)!=EOF)
    {
        for(i=1;i<=3;i++)
            pp[i].clear();
        for(i=1;i<=n;i++)
        {
            scanf("%d",&num[i]);
            pp[num[i]].push_back(i);
        }
        int a,b,c;
        int min1;
        a=pp[1].size();
        b=pp[2].size();
        c=pp[3].size();
        min1=min(a,b);
        min1=min(min1,c);
        printf("%d\n",min1);
        for(i=0;i<min1;i++)
        {
            printf("%d %d %d\n",pp[1][i],pp[2][i],pp[3][i]);
        }
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值