포럼
문제 ICPC00238

C. Card Hand Sorting

설명

When dealt cards in the card game Plump it is a good idea to start by sorting the cards in hand by suit and rank. The different suits should be grouped and the ranks should be sorted within each suit. But the order of the suits does not matter and within each suit, the cards may be sorted in either ascending or descending order on rank. It is allowed for some suits to be sorted in ascending order and others in descending order.

Sorting is done by moving one card at a time from its current position to a new position in the hand, at the start, end, or in between two adjacent cards. What is the smallest number of moves required to sort a given hand of cards?

제약
입력 형식

The first line of input contains an integer \(n\) (\(1 \le n \le 52\)), the number of cards in the hand. The second line contains \(n\) pairwise distinct space-separated cards, each represented by two characters. The first character of a card represents the rank and is either a digit from 2 to 9 or one of the letters T, J, Q, K, and A representing Ten, Jack, Queen, King and Ace, respectively, given here in increasing order. The second character of a card is from the set s, h, d, c representing the suits spades \(\spadesuit\), hearts \(\heartsuit\), diamonds \(\diamondsuit\), and clubs \(\clubsuit\).

출력 형식

Output the minimum number of card moves required to sort the hand as described above.

예제 1
입력
4
2h Th 8c Qh
출력
1
예제 2
입력
7
9d As 2s Qd 2c Jd 8h
출력
2
예제 3
입력
4
2h 3h 9c 8c
출력
0
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC NCPC 2016

평가 및 의견

C. Card Hand Sorting

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

C. Card Hand Sorting

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8