E - Team Olympiad

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

71 3 1 3 2 1 2

Output

23 5 26 7 4

Input

42 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\n",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\n");
    else
        printf("%d\n",j);
        shuchu(a,j,n);
    return 0;
}
时间: 2024-09-28 22:38:37

E - Team Olympiad的相关文章

Codeforces Team Olympiad(暴力)

***********************************************声明****************************************************** 原创作品,出自 "晓风残月xj" 博客,欢迎转载,转载时请务必注明出处(http://blog.csdn.net/xiaofengcanyuexj). 由于各种原因,可能存在诸多不足,欢迎斧正! *******************************************

Codeforces Round #516 (Div. 2, by Moscow Team Olympiad)

Codeforces Round #516 (Div. 2, by Moscow Team Olympiad) https://codeforces.com/contest/1064 A 1 #include<bits/stdc++.h> 2 #define pb push_back 3 using namespace std; 4 5 bool Check(int a,int b,int c){ 6 if(a+b>c&&b+c>a&&a+c>

CodeForces 490A Team Olympiad

题意: 编号为1.2.3的同学分成一组  问  最多形成多少组  并输出方案 思路: 模拟3个栈暴力 代码: #include<cstdio> #include<iostream> #include<cstring> #include<string> #include<algorithm> #include<map> #include<set> #include<vector> #include<queu

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

#include<stdio.h> #include<iostream> #include<memory.h> #include<math.h> using namespace std; int flag1[5000]; int flag2[5000]; int flag3[5000]; int main() { memset(flag1,0,sizeof(flag1)); memset(flag2,0,sizeof(flag2)); memset(flag

Codeforces Round #516 (Div. 1, by Moscow Team Olympiad) B

题链 Description 给一张方格图,对于上下移动无限制,左右移动数分别不能超过L,R,求能到多少点. Sol 发现 新的y坐标=老坐标-左移操作数+右移操作数 所以我们只需最小化左移操作数即可,最短路. Code #include<bits/stdc++.h> #define N 2007 #define pii pair<int,int> #define fi first #define se second using namespace std; char p[N][N

Codeforces Round #516 (Div. 1, by Moscow Team Olympiad) C

题链 Description 和交互库交互,你给出n个点,交互库指定颜色,求一条直线分割颜色. Sol 分别在x轴,y轴上二分即可. Code #include<bits/stdc++.h> #define Mid (l+r>>1) using namespace std; int n,l,r; char p1[102],p2[102],p3[102]; void work(int x,int pos,int g) { l=500000000; r=1000000000; for

Codeforces Round #516 (Div. 1, by Moscow Team Olympiad) D

题链 Description 解一个线性规划(大雾) Sol 单纯形我们发现我们可以暴力枚举转的圈数,而这个东西可以数论分块优化. Code #include <bits/stdc++.h> #define LL long long using namespace std; LL n,x,k,lb,ub,l,r,ans=-1; int main() { scanf("%lld%lld%lld%lld",&n,&l,&r,&k); x=(r&g

Codeforces Round #516 (Div. 2, by Moscow Team Olympiad) D. Labyrinth

http://codeforces.com/contest/1064/problem/D 向上/向下加0,向左/右加1, step = 0,1,-- 求的是最少的步数,所以使用bfs. step=k -> step=k+1 1.step=k 使用一次左/右 到达 step=k+1 2.step=k+1 无限使用上下,得到所有 step=k+1 的状态 用dijkstra+堆优化 / spfa 超时. 1 #include <bits/stdc++.h> 2 using namespace

Codeforces Round #516 (Div. 1, by Moscow Team Olympiad) E

题链 Description 给一个排列,要求每个激光打到指定的接受器上,最大化这个数量,你的手段只有在n*n的位置上放平面镜. Sol 我们发现一行要么只放‘/’要么只放‘\’,又发现answer=n||answer=n-1,这可以倒着合并. Description #include<bits/stdc++.h> #define N 1006 using namespace std; int n,a[N],last; char ans[N][N]; signed main () { scan