• E


    Description

    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 integerst1, 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 Input

    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
    #include<stdio.h>
    int a[5500];
    int min(int a,int b)
    {
        int c;
        b<a?c=b:c=a;
        return c;
    }
    void shuchu(int a[],int j,int n)
    {
        int i,t;
        for(i=0; i<j; i++)
        {
            for(t=0; t<n; t++)
            {
                if(a[t]==1)
                {
                    printf("%d ",t+1);
                    a[t]=0;
                    break;
                }
            }
            for(t=0; t<n; t++)
            {
                if(a[t]==2)
                {
                    printf("%d ",t+1);
                    a[t]=0;
                    break;
                }
            }
            for(t=0; t<n; t++)
            {
                if(a[t]==3)
                {
                    printf("%d
    ",t+1);
                    a[t]=0;
                    break;
                }
            }
        }
    }
    int main()
    {
        int i,j,t,n,a1,b1,c1;
        scanf("%d",&n);
        for(i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
        }
        a1=0;b1=0;c1=0;
        for(i=0; i<n; i++)
        {
            if(a[i]==1)a1++;
            else if(a[i]==2)b1++;
            else  c1++;
        }
        j=min(a1,min(b1,c1));
        if(j==0)printf("0
    ");
        else
            printf("%d
    ",j);
            shuchu(a,j,n);
        return 0;
    }
  • 相关阅读:
    XML和解析
    代理模式
    net-snmp配置文件snmp.conf
    tomcat-在eclispe中配置远程调试
    tomcat-在eclipse中配置tomcat容器的内存
    web项目跨域访问
    STS-创建spring配置文件
    STS-新建mvc工程--helloworld
    STS-新建spring mvc项目
    Eclipse-安装Spring Tool Suit 插件
  • 原文地址:https://www.cnblogs.com/dongq/p/4134014.html
Copyright © 2020-2023  润新知