Codeforces Round #279 (Div. 2)-A. Team Olympiad (贪心)_html/css_WEB-ITnose

WBOY
풀어 주다: 2016-06-24 11:53:30
원래의
1178명이 탐색했습니다.

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

    71 3 1 3 2 1 2
    로그인 후 복사

    output

    23 5 26 7 4
    로그인 후 복사

    input

    42 1 1 2
    로그인 후 복사

    output





    题目大意:有一组数,分为三类1,2,3,现将其分队,每队三人必须1,2,3全部包含,问最多能分多少队,并输出如何各队成员的编号。


    解题思路:直接将三种数的编号分别放到三个数组中,能分的队数取决于最少的一类数的个数。直接对应输出即可。




    AC代码:

    #include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <sstream>#include <iomanip>#include <numeric>#include <cstring>#include <climits>#include <cassert>#include <complex>#include <cstdio>#include <string>#include <vector>#include <bitset>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <list>#include <set>#include <map>using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")typedef long long LL;typedef double DB;typedef unsigned uint;typedef unsigned long long uLL;/** Constant List .. **/ //{const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const DB EPS = 1e-9;const DB OO = 1e20;const DB PI = acos(-1.0); //M_PI;const int maxn= 10000001;int a[maxn] , b[maxn] , c[maxn];int main(){#ifdef sxk    freopen("in.txt","r",stdin);#endif //sxk    int n;    while(~scanf("%d",&n))    {        memset(a , 0 , sizeof(a));        memset(b , 0 , sizeof(b));        memset(c , 0 , sizeof(c));        int k;        int s1 = 0 , s2 = 0 , s3 = 0;        for(int i = 1 ; i   <br>  <br>  <p></p>  <p><br> </p>  <p><br> </p> </map></set></list></ctime></cmath></stack></queue></bitset></vector></string></cstdio></complex></cassert></climits></cstring></numeric></iomanip></sstream></fstream></iostream></algorithm></functional>
    로그인 후 복사
    원천:php.cn
    본 웹사이트의 성명
    본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
    인기 튜토리얼
    더>
    최신 다운로드
    더>
    웹 효과
    웹사이트 소스 코드
    웹사이트 자료
    프론트엔드 템플릿
    회사 소개 부인 성명 Sitemap
    PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!