CFGym 102299 H Course recommendation

11 篇文章 0 订阅

Description

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 N

and M

, 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

  • 2≤N≤100
  •  
  • 1≤M≤100
  •  
  • 1≤Qi,c≤M
  •  
  • 0≤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).

Sample Input

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

Hint

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

 

In the second, it is given by √(7−5)2+(8−9)2

题意:n个人,m个课程,第i个人学了k门课程,每门成绩是bi,现在,他要推荐他成绩最高且对方没学学过的课程给离他最近的同学,距离定义为:两个个人学的共同课程中,每门课差的平方的和。问每个人被推荐的课程是什么

思路:直接模拟,注意一个如果一个人和多个人距离相同,那么选序号最小的同学就行

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long
#define maxn 150
struct node
{
    int fs,id;
}a[maxn];
int b[maxn][maxn];
int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    memset(b,-1,sizeof(b));
    for(int i=1;i<=n;i++)
    {
        int k;
        scanf("%d",&k);
        for(int j=1;j<=k;j++)
        {
            int x,y;
            scanf("%d %d",&x,&y);
            b[i][x]=y;
        }
    }
    for(int i=1;i<=n;i++)
    {
        int min1=99999999;
        for(int j=1;j<=n;j++)
        {
            if(i==j) continue;
            int sum=0,flag=0;
            for(int k=1;k<=m;k++)
            {
                if(b[i][k]!=-1&&b[j][k]!=-1)
                {
                    sum+=(b[i][k]-b[j][k])*(b[i][k]-b[j][k]);
                    flag=1;
                }
            }
            if(min1>sum&&flag==1)
            {
                min1=sum;
            }
        }int max2=-1;
        for(int j=1;j<=n;j++)
        {
            if(i==j) continue;
            int sum=0,flag=0;
            for(int k=1;k<=m;k++)
            {
                if(b[i][k]!=-1&&b[j][k]!=-1)
                {
                    flag=1;
                    sum+=(b[i][k]-b[j][k])*(b[i][k]-b[j][k]);
                }
            }
            if(sum==min1&&flag==1)
            {
                for(int k=1;k<=m;k++)
                {
                    if(max2<b[j][k]&&b[i][k]==-1&&b[j][k]!=-1)
                    {
                        a[i].id=k;
                        max2=b[j][k];
                    }
                    else if(max2==b[j][k]&&b[i][k]==-1&&b[j][k]!=-1)
                    {
                        if(k<a[i].id) a[i].id=k;
                    }
                }
                break;
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i].id==0) printf("-1\n");
        else printf("%d\n",a[i].id);
    }
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
毕业设计,基于SpringBoot+Vue+MySQL开发的公寓报修管理系统,源码+数据库+毕业论文+视频演示 现代经济快节奏发展以及不断完善升级的信息化技术,让传统数据信息的管理升级为软件存储,归纳,集中处理数据信息的管理方式。本公寓报修管理系统就是在这样的大环境下诞生,其可以帮助管理者在短时间内处理完毕庞大的数据信息,使用这种软件工具可以帮助管理人员提高事务处理效率,达到事半功倍的效果。此公寓报修管理系统利用当下成熟完善的Spring Boot框架,使用跨平台的可开发大型商业网站的Java语言,以及最受欢迎的RDBMS应用软件之一的MySQL数据库进行程序开发。公寓报修管理系统有管理员,住户,维修人员。管理员可以管理住户信息和维修人员信息,可以审核维修人员的请假信息,住户可以申请维修,可以对维修结果评价,维修人员负责住户提交的维修信息,也可以请假。公寓报修管理系统的开发根据操作人员需要设计的界面简洁美观,在功能模块布局上跟同类型网站保持一致,程序在实现基本要求功能时,也为数据信息面临的安全问题提供了一些实用的解决方案。可以说该程序在帮助管理者高效率地处理工作事务的同时,也实现了数据信息的整体化,规范化与自动化。 关键词:公寓报修管理系统;Spring Boot框架;MySQL;自动化;VUE
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值