A - Diverse Team
Problem description
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.
Input
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.
Output
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.
Examples
Input
5 3
15 13 15 15 12
Output
YES
1 2 5
Input
5 4
15 13 15 15 12
Output
NO
Input
4 4
20 10 40 30
Output
YES
1 2 3 4
Note
All possible answers for the first example:
- {1 2 5}
- {2 3 5}
- {2 4 5}
Note that the order does not matter.
解题思路:题目的意思就是从n个学生中找出k个不同的数字,如果有输出"YES",并且依次输出他们的序号,否则输出"NO",简单水过!
AC代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k,x,m=,a[],b[];bool flag;//a数组存放不重复的元素,b数组记录每个元素的位置
cin>>n>>k;
for(int i=;i<=n;++i){
cin>>x;flag=false;
for(int j=;j<m;++j)
if(a[j]==x){flag=true;break;}
if(!flag){b[m]=i;a[m++]=x;}
}
if(m>=k){
cout<<"YES"<<endl;
for(int i=;i<k;++i)
cout<<b[i]<<(i==k-?"\n":" ");
}
else cout<<"NO"<<endl;
return ;
}
A - Diverse Team的更多相关文章
- Codeforces Round #486 (Div. 3) A. Diverse Team
Codeforces Round #486 (Div. 3) A. Diverse Team 题目连接: http://codeforces.com/contest/988/problem/A Des ...
- 微软职位内部推荐-SENIOR PRODUCER
微软近期Open的职位: Role Based in Shanghai, ChinaTitle: ProducerWe are seeking a Senior Producer to lead Pr ...
- Configure a VLAN on top of a team with NetworkManager (nmcli) in RHEL7
SOLUTION VERIFIED September 13 2016 KB1248793 Environment Red Hat Enterprise Linux 7 NetworkManager ...
- Create a Team in RHEL7
SOLUTION VERIFIED September 13 2016 KB2620131 Environment Red Hat Enterprise Linux 7 NetworkManager ...
- Team Leader 你不再只是编码, 来炖一锅石头汤吧
h3{ color: #000; padding: 5px; margin-bottom: 10px; font-weight: bolder; background-color: #ccc; } h ...
- Configure bridge on a team interface using NetworkManager in RHEL 7
SOLUTION IN PROGRESS February 29 2016 KB2181361 environment Red Hat Enterprise Linux 7 Teaming,Bridg ...
- BZOJ 4742: [Usaco2016 Dec]Team Building
4742: [Usaco2016 Dec]Team Building Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 21 Solved: 16[Su ...
- 关于 feature team 的一些内容
矩阵式管理,是常见的经典管理架构.其最早起源于美国的航空航天部门,然后被美国人带到了日本,然后被日本人带到了台湾,然后台湾人带到大陆...矩阵管理最典型的特征是,组织架构按职能与专业划分,项目由跨越部 ...
- 病毒四度升级:安天AVL Team揭露一例跨期两年的电信诈骗进化史
自2014年9月起,安天AVL移动安全团队持续检测到一类基于Android移动平台的间谍类病毒,病毒样本大多伪装成名为"最高人民检察院"的应用.经过反编译逆向分析以及长期的跟踪调查 ...
随机推荐
- CAD插入非等比例的图块
主要用到函数说明: _DMxDrawX::InsertBlock 向控件数据库中插入一个图块,不用它插入匿名块.详细说明如下: 参数 说明 BSTR pszDwgFileName 图块定义的dwg 文 ...
- ubuntu14.04远程软件VNC的安装、设置方法
ubuntu中VNCX11開機啟動保持靜默狀態方法: 1首先安裝vncx11. 2.設置vnc密碼,會自動保存在/home/test/.vnc/passwd中 3.將密碼複製到/etc中 4.在/et ...
- Python 模块的导入 day5
一.模块 1.标准模块 python自带的 2.第三方模块 需要自己安装的模块 3.自己写的python文件 一个python文件,就是一个模块 (1)导入模块的实质 就是把你导入的模块运行了一遍 ( ...
- enote笔记语言(3)
what&why(why not)&how&when&where&which:紫色,象征着神秘而又潜蕴着强大的力量,故取紫色. key&key-memo ...
- 浏览器控制之 selenium,phantomJs谷无头浏览器
目录 浏览器控制之 selenium,phantomJs谷无头浏览器 selenium phantomJs 需求是尽可能多的爬取豆瓣网中的电影信息 谷歌无头浏览器 浏览器控制之 selenium,ph ...
- ActiveMQ学习总结(10)——ActiveMQ采用Spring注解方式发送和监听
对于ActiveMQ消息的发送,原声的api操作繁琐,而且如果不进行二次封装,打开关闭会话以及各种创建操作也是够够的了.那么,Spring提供了一个很方便的去收发消息的框架,spring jms.整合 ...
- JavaSE 学习笔记之Object对象(八)
Object:所有类的直接或者间接父类,Java认为所有的对象都具备一些基本的共性内容,这些内容可以不断的向上抽取,最终就抽取到了一个最顶层的类中的,该类中定义的就是所有对象都具备的功能. 具体方法: ...
- hdu 3657最大点权独立集变形(方格取数变形)
/* 分奇偶为二部图,s与奇建图,t与偶建图,权值为当前数的值,如果遇到必取的权值置为inf. 奇偶建边为相邻的权值为2*(x&y):所有数的值-最小点全覆盖. 置为inf意为不能割掉.奇偶边 ...
- JAVA的堆和栈(转)
堆栈是 两种数据结构.堆栈都是一种数据项按序排列的数据结构,只能在一端(称为栈顶(top))对数据项进行插入和删除.在单片机应用中,堆栈是个特殊的存储 区,主要功能是暂时存放数据和地址,通常用来保护断 ...
- Oracle_Data_Gard Create a physical standby database
创建之前要对DG的环境有一个总体的规划和了解. 规划 IP 192.168.3.161 192.16 ...