zoukankan      html  css  js  c++  java
  • Course recommendation Gym

     One of the biggest challenges in an online course platform is to recommend to a student one of its over 800 courses.

     For instance, João took courses on Java and Java for the Web, with grades 10 and 9, respectively. What should he be recommended next? If we recommend him something much easier, much harder, or simply something that does not go with his profile, we will waste his time. Just as an undergraduate student is very careful for choosing the appropriate courses and not waste a semester due to poor choices, we wish to help students in this platform to make the best choices.

     In this problem, we have (N) students and (M) courses. Students are numbered from 1 to (N), the courses from (1) to (M). For each student, we know which courses he or she already took and the respective grades. To recommend a course to a student, we first find another student who is closest to him or her. The distance between two students is defined as the euclidean distance between the grades of the courses both students took. If there are no shared courses, the distance is defined as infinity. Among the courses already taken by the closest student, we recommend the course with the highest grade which was not already taken by the original student. In case of a tie, recommend the course with the smallest index. If the original student already took all the courses that were taken by his closest student, no recommendation is make.

     Your task is to code a program that recommend a course to all the students in the platform.

    Input

     The first line has two integers NN and MM, the number of students and courses, respectively. After this there are (N) blocks of lines, each one contains a line with an integer (Q_i), the amount of courses already taken by the (i)th student, and then (Q_i) lines, each one containing two integers (c) and (g), which indicate that the (i)th student got grade (g) for course (c).

    Constraints

    • 2N1002≤N≤100
    • 1M1001≤M≤100
    • 1Qi,cM1≤Qi,c≤M
    • 0g100≤g≤10
    • You may assume that each student has already taken at least one course that another student took.

    Output

    Print (N) lines, where the (i)th line has the course recommended to the (i)th student. If student (i) has already taken all courses that his closest student already took, print (-1).

    Examples

    Input
    2 3
    2
    1 10
    2 10
    2
    2 9
    3 5
    
    Output
    3
    1
    
    Input
    2 4
    3
    1 7
    2 8
    3 10
    3
    4 10
    2 9
    1 5
    
    Output
    4
    3
    

    Note

    In the first example, the distance between students is given by (10−9)2

    In the second, it is given by√ (75)2+(89)2

    题意:

    人们在选课,人们(甲)会听从最亲近的人(乙)的建议,乙会向甲推荐甲没学过的并且自己分数高的一门科目

    问推荐的啥

    思路:

    这道题不需要思路(读懂题目就够了,这题考英语呢),100的范围,啥都敢写,暴力得了

     1 #include <stdio.h>
     2 #include <string.h>
     3 const int INF = 0x3f3f3f3f;
     4 
     5 int main()
     6 {
     7     int n, m, a[105][105], i, j, k, x;
     8     int ke, fen, minx;
     9     int minn;
    10     int rela[105][105];
    11     memset(a, -1, sizeof(a));
    12     memset(rela, INF, sizeof(rela));
    13     scanf("%d %d", &n, &m);
    14     for(i=1; i<=n; i++)
    15     {
    16         scanf("%d", &x);
    17         while(x--)
    18         {
    19             scanf("%d %d", &ke, &fen);
    20             a[i][ke] = fen;
    21         }
    22     }
    23 
    24     for(i=1; i<=n; i++)
    25     {
    26         for(j=1; j<=n; j++)
    27         {
    28             for(k=1; k<=m; k++)
    29             {
    30                 if(i!=j&&a[i][k]!=-1&&a[j][k]!=-1)
    31                 {
    32                     if(rela[i][j]==INF)
    33                         rela[i][j] = (a[i][k]-a[j][k]) * (a[i][k]-a[j][k]);
    34                     else rela[i][j] = rela[i][j] + (a[i][k]-a[j][k]) * (a[i][k]-a[j][k]);
    35                 }
    36             }
    37         }
    38     }
    39 
    40     for(i=1; i<=n; i++)
    41     {
    42         minn = INF;
    43         for(j=1; j<=n; j++)
    44         {
    45             if(rela[i][j] < minn && i!=j)
    46             {
    47                 minn = rela[i][j];
    48                 minx = j;
    49             }
    50         }
    51         if(minn==INF) printf("-1
    ");
    52 
    53         else
    54         {
    55             int mink = INF, maxf = -1;
    56             for(j=1; j<=m; j++)
    57             {
    58                 if(a[i][j]!=-1) continue;
    59                 if(a[minx][j]>maxf)
    60                 {
    61                     maxf = a[minx][j];
    62                     mink = j;
    63                 }
    64             }
    65             if(mink==INF||maxf==-1) printf("-1
    ");
    66             else printf("%d
    ", mink);
    67         }
    68     }
    69 
    70     return 0;
    71 }
  • 相关阅读:
    Convert to a source folder or rename it.
    git revert 后悔了 还原修改前的版本 + git 常用命令
    android switch语句报错:case expressions must be constant expressions
    解读ContentResolver和ContentProvider
    sdk命令
    向Android模拟器中批量导入通讯录联系人
    Rational Rose2007下载安装教程以及问题处理
    java代码打包成jar以及转换为exe
    Timusoj 1982. Electrification Plan
    poj 3254 Corn Fields
  • 原文地址:https://www.cnblogs.com/0xiaoyu/p/11390721.html
Copyright © 2011-2022 走看看