Diverse Team(CF-988A)
Problem Description
There are nn students in a school class, the rating of the i-th student on Codehorses is aiai. You have to form a team consisting of kk 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 kk 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 aiai 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?
題意:給出 n 個學生的成績,要在 n 個學生里選 k 個人組成一隊,要求 k 個人的成績均不相同,如果可以,輸出 YES 以及選的人的編號,如果不行,輸出 NO
思路:設置一標記數組,記錄分數不同的人的編號以及個數,如果小于 k,則輸出 NO,如果滿足條件,依次輸出即可。
Source Program
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<string> #include<cstdlib> #include<queue> #include<set> #include<map> #include<stack> #include<ctime> #include<vector> #define INF 0x3f3f3f3f #define PI acos(-1.0) #define N 10005 #define MOD 123 #define E 1e-6 using namespace std; int a[N]; int vis[N]; int ans[N]; int main() {int n,k;cin>>n>>k;int cnt=0;for(int i=1;i<=n;i++){cin>>a[i];if(!vis[a[i]])//如果分數未出現過{cnt++;//不同的分數+1ans[cnt]=i;//記錄位置}vis[a[i]]=1;//標記}if(cnt<k)//不同分數小于要求數cout<<"NO"<<endl;else{cout<<"YES"<<endl;for(int i=1;i<=k;i++)cout<<ans[i]<<" ";cout<<endl;}return 0; }?
總結
以上是生活随笔為你收集整理的Diverse Team(CF-988A)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 数的划分(洛谷-P1025)
- 下一篇: 单词接龙(信息学奥赛一本通-T1220)