zoukankan      html  css  js  c++  java
  • Codeforces Round #279 (Div. 2) A

    最近水水的开始写CF,感觉自己什么都不会,现在连水题都切不动了。。。。

    写一下我做的两道水题。。

    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

    题目意思就是选出最多的含有1,2,3的种数,然后输出它们各自的下标。题目很简单,用一个二维数组M[4][N]和d[4]来实现,M的行用来读入1,2,3,M的列用来记录出现的次数,每次出现一次的d[k]++。然后用用ans找到1,2,3出现的次数最小的值,然后输出。
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cmath>
     5 
     6 using namespace std;
     7 
     8 
     9 
    10 #define N 5010
    11 
    12 int m[4][N], d[4];
    13 int n;
    14 
    15 int main() {
    16 
    17   scanf("%d", &n);
    18   for (int i = 1; i <= n; i++) {
    19     int k;
    20     scanf("%d", &ff);
    21     man[k][d[k]] = i;
    22     d[k]++;
    23 
    24 
    25   }
    26   int ans = min(d[1], min(d[2], d[3]));
    27   printf("%d
    ", ans);
    28   for (int i = 0; i < ans; i++)
    29     printf("%d %d %d
    ", m[1][i], m[2][i], m[3][i]);
    30   return 0;
    31 }
    It is loneliness that make you different,not gregariousness
  • 相关阅读:
    win7下64位系统memcache/memcached安装教程
    支付宝接口使用文档说明 支付宝异步通知(notify_url)与return_url.
    PHP使用DES进行加密解密
    使用PHP对文件进行压缩解压(zip)
    发一个天气预报接口
    使用php发送电子邮件(phpmailer)
    在线支付接口详解
    php 操作数组 (合并,拆分,追加,查找,删除等)
    PHP5中魔术方法
    Ehlib 学习
  • 原文地址:https://www.cnblogs.com/lmlyzxiao/p/4120712.html
Copyright © 2011-2022 走看看