Diverse Team(暴力)
There are n students in a school class, the rating of the i-th student on Codehorses is ai. You have to form a team consisting of k students ( 1≤k≤n
) such that the ratings of all team members are distinct.
If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print k
distinct numbers which should be the indices of students in the team you form. If there are multiple answers, print any of them.
The first line contains two integers n
and k ( 1≤k≤n≤100
) — the number of students and the size of the team you have to form.
The second line contains n
integers a1,a2,…,an ( 1≤ai≤100), where ai is the rating of i
-th student.
If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print k
distinct integers from 1 to n
which should be the indices of students in the team you form. All the ratings of the students in the team should be distinct. You may print the indices in any order. If there are multiple answers, print any of them.
Assume that the students are numbered from 1
to n
.
5 3 15 13 15 15 12
YES 1 2 5
5 4 15 13 15 15 12
NO
4 4 20 10 40 30
YES 1 2 3 4
All possible answers for the first example:
- {1 2 5}
- {2 3 5}
- {2 4 5}
Note that the order does not matter.
题意:一共给n个数,在n个数里找k个完全不相同的数,如果能找到,可以输出任意一组的下标,如果不能输出NO
思路:定义一个vis数组记录每个数字出现的下标,如果是0表示没有出现过,用type记录数字的种类,如果小于k则直接输出NO
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 105;
int vis[N];
int main(){int n,k;scanf("%d%d",&n,&k);int type=0;for(int i=0;i<n;i++){int x;scanf("%d",&x);if(!vis[x]){vis[x]=i+1;type++;}}if(type<k) printf("NO\n");else{printf("YES\n");int j=0;sort(vis,vis+101);for(int i=0;i<=100;i++)if(vis[i]){if(k==1) printf("%d\n",vis[i]);else if(k>1) printf("%d ",vis[i]);else break;k--;}}return 0;
}
Diverse Team(暴力)相关推荐
- Diverse Team(CF-988A)
Problem Description There are nn students in a school class, the rating of the i-th student on Codeh ...
- Codeforces Round #486 (Div. 3)【完结】
2022.3.2 题单地址:https://codeforces.com/contest/988 目录 A. Diverse Team[模拟] B. Substrings Sort[暴力枚举] C. ...
- 辍学的名人_我辍学去追求成为网络开发人员和设计师的梦想
辍学的名人 by Carlos Sz 由Carlos Sz 我辍学去追求成为网络开发人员和设计师的梦想 (I dropped out of college to pursue my dreams of ...
- 加油python_力扣——gas station (加油站) python实现
题目描述: 中文: 在一条环路上有 N 个加油站,其中第 i 个加油站有汽油 gas[i] 升. 你有一辆油箱容量无限的的汽车,从第 i 个加油站开往第 i+1 个加油站需要消耗汽油 cost[i] ...
- 如何进入游戏行业_进入设计行业
如何进入游戏行业 We're living in some weird-ass times. One of the unfortunate results of a global pandemic i ...
- 管道过滤模式 大数据_大数据管道配方
管道过滤模式 大数据 介绍 (Introduction) If you are starting with Big Data it is common to feel overwhelmed by t ...
- 基础算法 —— 模拟思维
[概述] 模拟,是根据实际问题建立模型,模拟实际按程序走一遍,最终求出答案. 思维,则是与逻辑思维有关,其需要针对题意.数据范围等抽丝剥茧抽离出有用的信息,从而得出一个结果. 对于一般的模拟,直接根据 ...
- 遇见OFFER,阿里云最强技术团队现身招聘,“职”为你来
简历投递入口: https://bss.csdn.net/delivery/resume/ali 在5·15 遇见OFFER大厂梦招聘活动中,近20家企业来到CSDN[遇见OFFER]直播招聘栏目,其 ...
- 2020阿里招聘岗位要求
简历投递入口: https://bss.csdn.net/delivery/resume/ali 职位名称 职位描述 职位要求 阿里云智能事业群-中间件业务中台架构师-北京\杭州 1.负责阿里云中台项 ...
- 性别歧义代词(GAP) 2019年 NLP 研讨会性别偏见问题共同任务--阅读笔记
Gendered Ambiguous Pronouns (GAP) Shared Task at the Gender Bias in NLP Workshop 2019 https://www.ac ...
最新文章
- SAP Query达到select * where 的效果 2011-04-29
- 【Android 应用开发】BluetoothAdapter解析
- 检测子进程的结束返回状态,status的取值可以是哪些?(简析)
- [工具]再更新音乐下载软件,MP3音乐无损音乐下载器
- 聪明的木匠(优先队列,思维)
- Android之用adb screencap -p命令截图
- Qt工作笔记-ui文件连接信号与槽
- jQuery插件开发详细教程
- MySQL 到底能不能放到 Docker 里跑? 1
- linux/windows下代理软件对比分析
- 清明节如何计算(一千年清明节计算)
- Docker基础笔记
- Microsoft Edge 收藏夹如何显示在界面上方?
- Webstorm 分屏操作
- SpringBoot 重置 kafka 偏移量offset(kafka-0.10.1.0)
- solr中文同义词检索的配置讲解
- 解决google打开Github慢的问题,亲测有效
- C语言剖析OC的rangeOfString方法
- Android开发k歌软件,安卓电视k歌软件哪个好?
- SEO免费外链发布工具