试题编号: 201909-4
试题名称: 推荐系统
时间限制: 5.0s
内存限制: 512.0MB


问题链接:CCF201909-4 推荐系统
问题简述:(略)
问题分析:模拟题,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)

100分的C++语言程序如下:

/* CCF201909-4 推荐系统 */#include <bits/stdc++.h>using namespace std;const int M = 50;
int a[M], cnt[M + 1];
vector<int> choose[M + 1];struct Goods {int type;int id;int score;bool operator < (const Goods &a) const {return score == a.score ? (type == a.type ? id < a.id : type < a.type) : score > a.score;}
};struct DelGoods {int type;int id;bool operator < (const DelGoods &a) const {return type == a.type ? id < a.id : type < a.type;}
};int main()
{std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);set<Goods> g;set<DelGoods> d;int m, n, type, id, score;cin >> m >> n;for (int i = 1; i <= n; i++) {cin >> id >> score;for (int j = 0; j < m; j++)g.insert(Goods{j, id, score});}int num, op, k;cin >> num;for (int i = 1; i <= num; i++) {cin >> op;if (op == 1) {        // 增加cin >> type >> id >> score;g.insert(Goods{type, id, score});} else if (op == 2) {     // 删除cin >> type >> id;d.insert(DelGoods{type, id});} else if (op == 3) {       // 查询memset(cnt, 0, sizeof cnt);for (int j = 0; j < m; j++) choose[j].clear();cin >> k;for (int j = 0; j < m; j++) cin >> a[j];for (set<Goods>::iterator iter = g.begin(); cnt[M] < k && iter != g.end();) {if (cnt[iter->type] < a[iter->type]) {if (d.find(DelGoods{iter->type, iter->id}) != d.end())g.erase(iter++);else {cnt[iter->type]++;cnt[M]++;choose[iter->type].push_back(iter->id);iter++;}} elseiter++;}// 输出结果for (int j = 0; j < m; j++) {if (cnt[j] == 0) cout << -1;else {for(vector<int>::iterator iter = choose[j].begin(); cnt[M] <= k && iter != choose[j].end(); iter++)cout << *iter << " ";}cout << "\n";}}}return 0;
}

100分的C++语言程序如下:

/* CCF201909-4 推荐系统 */#include <bits/stdc++.h>using namespace std;const int M = 50;
int a[M], cnt[M];struct Goods {int type;int id;int score;bool operator < (const Goods &a) const {return score == a.score ? (type == a.type ? id < a.id : type < a.type) : score > a.score;}
};int main()
{std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);set<Goods> g;map<pair<int, int>, int> mp;int m, n, type, id, score;cin >> m >> n;for (int i = 1; i <= n; i++) {cin >> id >> score;for (int j = 0; j < m; j++) {g.insert(Goods{j, id, score});mp[make_pair(j, id)] = score;}}int num, op, k;cin >> num;for (int i = 1; i <= num; i++) {cin >> op;if (op == 1) {        // 增加cin >> type >> id >> score;mp[make_pair(type, id)] = score;g.insert(Goods{type, id, score});} else if (op == 2) {     // 删除cin >> type >> id;score = mp[make_pair(type, id)];g.erase(Goods{type, id, score});} else if (op == 3) {       // 查询memset(cnt, 0, sizeof cnt);cin >> k;for (int j = 0; j < m; j++) cin >> a[j];vector<int> v[m];int sum = 0;for (set<Goods>::iterator iter = g.begin(); iter != g.end(); iter++) {type = iter->type;if (sum < k) {if (cnt[type] < a[type]) {sum++;cnt[type]++;v[type].push_back(iter->id);}} elsebreak;bool flag = true;for (int j = 0; j < m; j++)if (cnt[j] != a[j]) {flag = false;break;}if (flag) break;}for (int j = 0; j < m; j++) {if (v[j].size() == 0) cout << -1;else {for(int l = 0; l < (int)v[j].size(); l++)cout << v[j][l] << " ";}cout << "\n";}}}return 0;
}

CCF201909-4 推荐系统(100分)【模拟】相关推荐

  1. CCF201912-4 区块链(100分)【模拟】

    试题编号: 201912-4 试题名称: 区块链 时间限制: 10.0s 内存限制: 512.0MB 问题链接:CCF201912-4 区块链 问题简述:(略) 问题分析:模拟题,不解释. 程序说明: ...

  2. CCF201903-4 消息传递接口(100分)【模拟】

    试题编号: 201903-4 试题名称: 消息传递接口 时间限制: 1.0s 内存限制: 512.0MB 问题链接:CCF201903-4 消息传递接口 问题简述:(略) 问题分析:模拟题,比较费时间 ...

  3. CCF202104-3 DHCP服务器(100分)【模拟】

    试题编号: 202104-3 试题名称: DHCP服务器 时间限制: 1.0s 内存限制: 512.0MB 问题描述: 试题背景 动态主机配置协议(Dynamic Host Configuration ...

  4. CCF201712-3 Crontab(100分)【模拟+文本处理】

    样例输入 3 201711170032 201711222352 0 7 * * 1,3-5 get_up 30 23 * * Sat,Sun go_to_bed 15 12,18 * * * hav ...

  5. CCF201803-2 碰撞的小球(100分)【模拟】

    试题编号: 201803-2 试题名称: 碰撞的小球 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 数轴上有一条长度为L(L为偶数)的线段,左端点在原点,右端点在坐标L处.有 ...

  6. CCF201709-2 公共钥匙盒(100分)【模拟+优先队列】

    试题名称:公共钥匙盒 问题描述 有一个学校的老师共用N个教室,按照规定,所有的钥匙都必须放在公共钥匙盒里,老师不能带钥匙回家.每次老师上课前,都从公共钥匙盒里找到自己上课的教室的钥匙去开门,上完课后, ...

  7. CCF201712-2 游戏(100分)【模拟】

    试题编号: 201712-2 试题名称: 游戏 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 有n个小朋友围成一圈玩游戏,小朋友从1至n编号,2号小朋友坐在1号小朋友的顺时针 ...

  8. CCF201912-1 报数(100分)【模拟】

    报数 问题链接:CCF201912-1 报数 问题分析:     用模拟法解决. 程序说明:     变量num用于计数,变量count用于计数数数的数量,数组cnt[]用于统计每个人的报数数量. 参 ...

  9. CCF201703-2 学生排队(100分)

    试题编号: 201703-2 试题名称: 学生排队 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 体育老师小明要将自己班上的学生按顺序排队.他首先让学生按学号从小到大的顺序排 ...

最新文章

  1. python修改excel数据-python之实现对excel表格数据的修改
  2. VMware Workstation 与 Hyper-V 不兼容
  3. go和python组合开发_混合Python和Go
  4. 四象限运行模式_信息流广告推广怎么选择正确的出价模式?
  5. Java黑皮书课后题第10章:**10.23(实现String类)在Java库中提供了String类,给出你自己对下面方法的实现(将新类命名为MyString2)
  6. oracle数据库主键自增序列_Oracle数据库序列详解
  7. python怎么设置颜色深浅变化_机器学习中减弱不同图像数据色调及颜色深浅差异...
  8. Angular 2 组件之间如何通信
  9. yuv420和yuv420p的区别
  10. python中string库_Python——string库
  11. 分布式消息系统jafka快速起步(转)
  12. 数学建模与数学实验4.4习题2
  13. 计算机开放电子书 2017 归档
  14. C++关于函数声明定义的位置
  15. java.net.URISyntaxException: Illegal character in scheme name at index XX
  16. 通过 Dockerfile 搭建标注工具 brat 的镜像
  17. 计算机导论课后总结3
  18. python批量修改Excel文件后缀csv为xlsx
  19. OpenCV-Python教程:绘制直线、圆形、方形(line,circle,rectangle)
  20. 2-Druid 系统框架

热门文章

  1. 如果你身边有这样的人,赶紧让他说点什么,然后反过来买彩票
  2. 简书优秀IT专栏作者推荐
  3. 可运行的C语言程序的拓展名,可运行的c语言程序的扩展名为什么?
  4. java提示没有main,有main方法却还是提示没有
  5. 5大最流行手机webAPP框架之Ionic
  6. Memcached 集群架构方面的问题
  7. angularjs post返回html_Python 爬虫网页解析工具lxml.html(二)
  8. std::kill_dependency
  9. 计算机系统访问控制的功能,访问控制是为了限制访问主体对访问客体的访问权限,从而使计算机系统在合法范围内使用的安全措施,以下关于访问控制的叙述中,()是不正确的 - 信管网...
  10. php面试题做得差,php面试题,你能解决几个?