Team Olympiad

举报
辰chen 发表于 2022/06/19 22:35:49 2022/06/19
【摘要】 文章目录 一、Team Olympiad总结 一、Team Olympiad 本题链接:A. Team Olympiad 题目: A. Team Olympiad time li...


一、Team Olympiad

本题链接A. Team Olympiad

题目

A. Team Olympiad

time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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.

Examples
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;每个孩子都只能在一个队伍中,每个队伍由三个孩子组成,并且这三个孩子需要会不同的技能,问最多能组几个队出来,并写出这些队伍中孩子的编号

AC代码

#include <iostream>
#include <algorithm>

using namespace std;

const int N = 5010;

int a[N];
int p[5][N];
int cnt1, cnt2, cnt3;

int main()
{
    int n;
    cin >> n;
    
    for (int i = 1; i <= n; i ++ ) 
    {
        cin >> a[i];
        if (a[i] == 1) 
            p[0][cnt1 ++] = i;
        else if (a[i] == 2)
            p[1][cnt2 ++] = i;
        else if (a[i] == 3)
            p[2][cnt3 ++] = i;
    }
    
    int t = cnt1;
    t = min(t, cnt2);
    t = min(t, cnt3);
        
    cout << t << endl;
    for (int i = 0; i < t; i ++ )
    {
        for (int j = 0; j < 3; j ++ ) 
            cout << p[j][i] << ' ';
        
        puts("");
    }
    
    return 0;
}

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42

总结

p数组二维不可以开成N / 3

文章来源: chen-ac.blog.csdn.net,作者:辰chen,版权归原作者所有,如需转载,请联系作者。

原文链接:chen-ac.blog.csdn.net/article/details/118962436

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。