-
Codeforces Round #486 (Div. 3) - A. Diverse Team구현(Implementation) 2018. 6. 19. 11:21반응형
http://codeforces.com/contest/988/problem/A
1. 문제
A. Diverse Teamtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are students in a school class, the rating of the -th student on Codehorses is . You have to form a team consisting of students () 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 distinct numbers which should be the indices of students in the team you form. If there are multiple answers, print any of them.
2. 알고리즘
정수를 입력을 받아 SET 자료형에 넣은다.
SET 에 이미 있는 정수면 삽입하지 않는다.
3. 코드
123456789101112131415161718192021222324252627282930313233343536373839#include <iostream>#include <sstream>#include <string>#include <algorithm>#include <functional>#include <vector>#include <list>#include <queue>#include <map>#include <set>using namespace std;int main() {std::ios::sync_with_stdio(false); cin.tie(0);int n, k;cin >> n >> k;set<int> el;vector<int> ans;for (int i = 0; i < n; ++i) {int x;cin >> x;if (!el.count(x)) {ans.push_back(i);el.insert(x);}}if (int(ans.size()) < k) {cout << "NO\n";} else {cout << "YES\n";for (int i = 0; i < k; ++i)cout << ans[i] + 1 << " ";cout << endl;}return 0;}cs 반응형'구현(Implementation)' 카테고리의 다른 글
백준 10250번 : ACM 호텔 (0) 2018.06.20 백준 1011번 : Fly me to the Alpha Centauri (0) 2018.06.20 백준 1453번 : 피시방 알바 (0) 2018.06.18 백준 10156번 : 과자 (0) 2018.06.17 백준 2670번 : 연속부분최대곱 (0) 2018.06.17