엄청 오랜만에 참가한듯..~
250 대충 빨리 푸니깐 rating 오를꺼같아서.. 나머지는 그냥 접었다.. 챌도 시도했으면 좋은 결과가 있었을텐데..
어쨋든 rating 은 좀 올라서 다시 Yellow 복귀!!!!
아.. 새벽 2시 매치는 너무 힘들어.. ㅠㅠ
Level1 - KingSort
Problem Statement
Every good encyclopedia has an index. The entries in the index are usually sorted in alphabetic order. However, there are some notable exceptions. In this task we will consider one such exception: the names of kings.
In many countries it was common that kings of the same name received ordinal numbers. This ordinal number was written as a Roman numeral and appended to the actual name of the king. For example, "Louis XIII" (read: Louis the thirteenth) was the thirteenth king of France having the actual name Louis.
In the index of an encyclopedia, kings who share the same name have to be sorted according to their ordinal numbers. For example, Louis the 9th should be listed after Louis the 8th.
You are given a vector <string> kings. Each element of kings is the name of one king. The name of each king consists of his actual name, a single space, and a Roman numeral. Return a vector <string> containing the names rearranged into their proper order: that is, the kings have to be in ascending lexicographic order according to their actual name, and kings with the same name have to be in the correct numerical order.
The Roman numerals for 1 through 10 are I, II, III, IV, V, VI, VII, VIII, IX, and X.
-
The Roman numerals for 20, 30, 40, and 50 are XX, XXX, XL, and L.
-
The Roman numeral for any other two-digit number less than 50 can be constructed by concatenating the numeral for its tens and the numeral for its ones. For example, 47 is 40 + 7 = "XL" + "VII" = "XLVII".
-
Standard string comparison routines give the correct ordering for the actual names of kings.
-
Formally, given two different strings A and B we say that A is lexicographically smaller than B if either (A is a prefix of B) or (there is at least one index where A and B differ, and for the smallest such index the character in A has a lower ASCII value than the character in B).
Constraints
-
Each actual name of a king will be a string containing between 1 and 20 characters, inclusive.
-
Each actual name will start by an uppercase letter ('A'-'Z').
-
Each other character in each actual name will be a lowercase letter ('a'-'z').
-
kings will contain between 1 and 50 elements, inclusive.
-
Each element of kings will have the form "ACTUALNAME ORDINAL", where ACTUALNAME is an actual name as defined above, and ORDINAL is a valid Roman numeral representing a number between 1 and 50, inclusive.
-
The elements of kings will be pairwise distinct.
Examples
0)
{"Louis IX", "Louis VIII"}
Returns: {"Louis VIII", "Louis IX" }
Louis the 9th should be listed after Louis the 8th.
1)
{"Louis IX", "Philippe II"}
Returns: {"Louis IX", "Philippe II" }
Actual names take precedence over ordinal numbers.
These are the French monarchs who ruled between 1328 and 1483.
5)
{"Philippe II", "Philip II"}
Returns: {"Philip II", "Philippe II" }
"Philippe" and "Philip" are distinct names, and "Philip" is lexicographically smaller than "Philippe".
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
이름을 Sorting 하는 문제..
이문제의 핵심은 Roman digit을 아라비아 숫자로 변환하는데 있다.. 예전에 짜둔게 있어서 그냥 복.붙 했는데..
30% unused 어쩌구 warning 이 나서 한참 삽질했다.. -_-
line 84 를 넣으니깐 warning 이 사라짐.. 이것땜에 시간 엄청 까먹음..
"In the country of Absurdistan there are N airports. Each airport is either big or small. It is known that for each big airport there are at least B flights leaving it, and for each small airport there are at most S flights leaving it. Each flight is bidirectional and connects exactly two airports. No two flights connect the same pair of airports. It is possible to travel from any airport to any other airport using some sequence of flights. Determine the number of big airports. Find all solutions."
Let A(N,B,S) be the number of solutions the above task has for a given triple N, B, S. You are given six ints: Nlo, Nhi, Blo, Bhi, Slo and Shi. Your method must compute and return the sum of A(N,B,S) over all N, B, S such that all following constraints hold:
Nlo <= N <= Nhi
Blo <= B <= Bhi
Slo <= S <= Shi
S < B
Definition
Class:
BigAndSmallAirports
Method:
solve
Parameters:
int, int, int, int, int, int
Returns:
long long
Method signature:
long long solve(int Nlo, int Nhi, int Blo, int Bhi, int Slo, int Shi)
(be sure your method is public)
Notes
-
It is possible that all airports in the country are of the same kind (all big or all small).
Constraints
-
Nhi will be between 1 and 10,000,000, inclusive.
-
Nlo will be between 1 and Nhi, inclusive.
-
Bhi will be between 1 and 200, inclusive.
-
Blo will be between 1 and Bhi, inclusive.
-
Shi will be between 1 and 200, inclusive.
-
Slo will be between 1 and Shi, inclusive.
Examples
0)
20
20
3
3
2
2
Returns: 21
For N=20, B=3, S=2 each number of big airports (from 0 to N, inclusive) is possible. The image below shows one possible network of airports and flights with 3 big airports (squares) and 17 small airports (circles).
1)
1
1
10
10
2
2
Returns: 1
In the case N=1, B=10, S=2 there is a single airport. It cannot have 10+ outgoing flights, therefore it has to be small. If the airport is small, all conditions are satisfied. Therefore A(N,B,S)=1.
2)
10
10
8
8
3
3
Returns: 6
3)
10
100
13
15
18
22
Returns: 0
There are no triples (N,B,S) such that N, B, S lie within the given ranges and B < S. Therefore the answer is the sum of zero values, which equals 0.