23
0 0 2013 NTU-CSIE ACM Rookie Cup 2013 NTU-CSIE ACM Rookie Cup Date: 2013/12/22 Time: 5 hours Problems: There are 10 problems in this contest. Input: Standard input, as you know. Output: Standard output, as you know. Time Limit: See Table 1 below. "cin" is much slower than "scanf". If you use "cin", you may receive Time Limit Exceeded if the input data is large. Table 1. Problem Information Name Time Limit Problem A Guessing Number 1 sec Problem B Coding Style 1 sec Problem C Lolita Counting 10 sec Problem D Discovery 1 sec Problem E The Lolita Sequence 8 sec Problem F Lolita Clusters 3 sec Problem G The Magic Potion 1 sec Problem H Rectangle Man 2 sec Problem I Paper Slip 1 sec Problem J LSC Wants to See Cute Girls 3 sec

2013 NTU-CSIE ACM Rookie Cupb01902011/2013_rookiecup.pdf · 7 2013 NTU-CSIE ACM Rookie Cup Problem C Lolita Counting Time Limit: 10 second Memory limit: 65536 KB "Wow!!" "What a nightmare!",

  • Upload
    others

  • View
    12

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 2013 NTU-CSIE ACM Rookie Cupb01902011/2013_rookiecup.pdf · 7 2013 NTU-CSIE ACM Rookie Cup Problem C Lolita Counting Time Limit: 10 second Memory limit: 65536 KB "Wow!!" "What a nightmare!",

0

0 2013 NTU-CSIE ACM Rookie Cup

2013 NTU-CSIE ACM Rookie Cup Date: 2013/12/22 Time: 5 hours

Problems: There are 10 problems in this contest.

Input: Standard input, as you know.

Output: Standard output, as you know. Time Limit: See Table 1 below.

"cin" is much slower than "scanf". If you use "cin",

you may receive Time Limit Exceeded if the input

data is large.

Table 1. Problem Information

Name Time Limit

Problem A Guessing Number 1 sec

Problem B Coding Style 1 sec

Problem C Lolita Counting 10 sec

Problem D Discovery 1 sec

Problem E The Lolita Sequence 8 sec

Problem F Lolita Clusters 3 sec

Problem G The Magic Potion 1 sec

Problem H Rectangle Man 2 sec

Problem I Paper Slip 1 sec

Problem J LSC Wants to See Cute Girls 3 sec

Page 2: 2013 NTU-CSIE ACM Rookie Cupb01902011/2013_rookiecup.pdf · 7 2013 NTU-CSIE ACM Rookie Cup Problem C Lolita Counting Time Limit: 10 second Memory limit: 65536 KB "Wow!!" "What a nightmare!",

1

1 2013 NTU-CSIE ACM Rookie Cup

Problem A

Guessing Number Time Limit: 1 second Memory limit: 65536 KB

Guessing number is a classical game. It needs at least two players, one of who is the

answerer, the others are guesser. At the beginning, the answerer must decide an integer

with 4 digits and the digits must be distinct (called a 4-digit-distinct number). Then in

each round, all guessers will guess one number. If anyone guesses the number the

answerer decided, the game ends and the player will become the winner; otherwise, the

game continues. If nobody guesses the right number after certain rounds (which can be

decided by players before the game), the answerer will become the winner.

The winner of the game will become "the king of games", who has the ability to give

other players "dark penalty". Dark penalty is usually horrible, and nobody can avoid the

penalty, so everyone wants to be the winner of the game, which is the real reason why

people have fun playing this boring game.

One day, wretched LSC walks around CSIE department building, and finds that there

are some lolitas around. So smart he is that he soon comes up with a mean idea: he can

play guessing game with them, become the winner, and apply some really really dark

penalty on the cute lolitas! However, he soon finds something troublesome – lolitas are

too young that they even don't know what a 4-digit-distinct number is! So before

practicing his mean idea, he must teach them what is a 4-digit-distinct number, and he

needs a program to help the lolitas to study.

Input Description

The first number of input data is an integer , denoting the number of test cases.

For each test case, there is only an integer in one line.

Output Description

For each test case, output an integer in a single line, which is the smallest

4-digit-distinct number bigger than .

Sample Input

3

1000

1997

2013

Page 3: 2013 NTU-CSIE ACM Rookie Cupb01902011/2013_rookiecup.pdf · 7 2013 NTU-CSIE ACM Rookie Cup Problem C Lolita Counting Time Limit: 10 second Memory limit: 65536 KB "Wow!!" "What a nightmare!",

2

2 2013 NTU-CSIE ACM Rookie Cup

Sample Output

1023

2013

2014

Page 4: 2013 NTU-CSIE ACM Rookie Cupb01902011/2013_rookiecup.pdf · 7 2013 NTU-CSIE ACM Rookie Cup Problem C Lolita Counting Time Limit: 10 second Memory limit: 65536 KB "Wow!!" "What a nightmare!",

3

3 2013 NTU-CSIE ACM Rookie Cup

Problem B

Coding Style Time Limit: 1 second Memory limit: 65536 KB

LSC sometimes has a part-time job for money, which is usually used to buy candies,

ice cream, etc. to carry off lolitas, and most of time the job is to develop a project. Since

many lolitas think programming is cool, he often shows his coding skill to lolitas when he

is working.

One day, while he is tricking lolitas again, his project partner, Lnsuyn, sends him a

code, asking for debug help. "Well, a nice chance to make lolitas adore me more!" he

thinks, so he accepts the case without too much considering.

However, something horrible happens – this is the hardest code he has ever seen!

There are no functions in the code, and the coding style is really strange; there are a lot

of complex operations, but no instruction code at all. The code just looks like a text

generated randomly, but Lnsuyn says it is meaningful. Nevertheless, this is not the worst.

LSC soon finds that the key part of the code is an if sentence, but the sentence is sooooo

disgusting that it's impossible to debug directly.

"What the f…ox says?" LSC is totally enraged by the code, but he can't show his

furious face in front of lolitas, so he needs a program to help him. Given Lnsuyn's code

and the variable values before the if sentence, please tell LSC whether the condition

sentence will be true.

Input Description

The first number of input data is an integer , denoting the number of test cases.

For each test case, there are 16 integers in one line, which are the values of ,

, , , , , , , , , , ,

, , . Please assume that input data won't lead to overflow of long long int

in C/C++ during all operations.

Output Description

For each test case, output "Yes" (without quotation) in a single line if the condition

sentence will be true; otherwise, output "No" in a single line (without quotation).

Sample Input

1

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Page 5: 2013 NTU-CSIE ACM Rookie Cupb01902011/2013_rookiecup.pdf · 7 2013 NTU-CSIE ACM Rookie Cup Problem C Lolita Counting Time Limit: 10 second Memory limit: 65536 KB "Wow!!" "What a nightmare!",

4

4 2013 NTU-CSIE ACM Rookie Cup

Sample Output

No

Code

int main(){

long long cx[4], cy[4], ak[3], bk[3], ck2, ck5;

if

(ak[0]*((cx[0]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[0]-cy[1]))*((cx[0]-cx[1])*(cy

[3]-cy[2])-(cx[3]-cx[2])*(cy[0]-cy[1]))==(cx[3]*((cx[0]-cx[1])*(cy[3]-cy[2])-(cx[3]

-cx[2])*(cy[0]-cy[1]))-cx[1]*((cx[0]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[0]-cy[1

]))-(cx[0]-cx[1])*((cx[2]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[2]-cy[1])))*(cx[3]*

((cx[0]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[0]-cy[1]))-cx[1]*((cx[0]-cx[1])*(cy[

3]-cy[2])-(cx[3]-cx[2])*(cy[0]-cy[1]))-(cx[0]-cx[1])*((cx[2]-cx[1])*(cy[3]-cy[2])-(

cx[3]-cx[2])*(cy[2]-cy[1])))+(cy[3]*((cx[0]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[

0]-cy[1]))

-cy[1]*((cx[0]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[0]-cy[1]))-(cy[0]-cy[1])*((cx

[2]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[2]-cy[1])))*(cy[3]*((cx[0]-cx[1])*(cy[3]-

cy[2])-(cx[3]-cx[2])*(cy[0]-cy[1]))-cy[1]*((cx[0]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2]

)*(cy[0]-cy[1]))-(cy[0]-cy[1])*((cx[2]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[2]-cy

[1])))&&ak[1]==ck2&&ak[2]*((cx[0]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[0]-cy

[1]))*((cx[0]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[0]-cy[1]))==

(cx[0]*((cx[0]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[0]-cy[1]))-cx[1]*((cx[0]-cx[1

])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[0]-cy[1]))-(cx[0]-cx[1])*((cx[2]-cx[1])*(cy[3]-c

y[2])-(cx[3]-cx[2])*(cy[2]-cy[1])))*(cx[0]*((cx[0]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2

])*(cy[0]-cy[1]))-cx[1]*((cx[0]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[0]-cy[1]))-(c

x[0]-cx[1])*((cx[2]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[2]-cy[1])))+(cy[0]*((cx[

0]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[0]-cy[1]))-cy[1]*((cx[0]-cx[1])*(cy[3]-cy

[2])-(cx[3]-cx[2])*(cy[0]-cy[1]))-(cy[0]-cy[1])*((cx[2]-cx[1])*(cy[3]-cy[2])-(cx[3]-

cx[2])*(cy[2]-cy[1])))*(cy[0]*((cx[0]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[0]-cy[

1]))-cy[1]*((cx[0]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[0]-cy[1]))

-(cy[0]-cy[1])*((cx[2]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[2]-cy[1])))&&bk[0]*(

(cx[0]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[0]-cy[1]))*((cx[0]-cx[1])*(cy[3]-cy[2

])-(cx[3]-cx[2])*(cy[0]-cy[1]))==(cx[2]*((cx[0]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*

(cy[0]-cy[1]))-cx[1]*((cx[0]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[0]-cy[1]))-(cx[

0]-cx[1])*((cx[2]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[2]-cy[1])))*(cx[2]*((cx[0]-

cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[0]-cy[1]))-cx[1]*((cx[0]-cx[1])*(cy[3]-cy[2]

)-(cx[3]-cx[2])*(cy[0]-cy[1]))-(cx[0]-cx[1])*((cx[2]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[

2])*(cy[2]-cy[1])))+(cy[2]*((cx[0]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[0]-cy[1])

Page 6: 2013 NTU-CSIE ACM Rookie Cupb01902011/2013_rookiecup.pdf · 7 2013 NTU-CSIE ACM Rookie Cup Problem C Lolita Counting Time Limit: 10 second Memory limit: 65536 KB "Wow!!" "What a nightmare!",

5

5 2013 NTU-CSIE ACM Rookie Cup

)-cy[1]*((cx[0]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[0]-cy[1]))-(cy[0]-cy[1])*((c

x[2]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[2]-cy[1])))*(cy[2]*((cx[0]-cx[1])*(cy[3

]-cy[2])-(cx[3]-cx[2])*(cy[0]-cy[1]))-cy[1]*((cx[0]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[

2])*(cy[0]-cy[1]))-(cy[0]-cy[1])*((cx[2]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[2]-

cy[1])))

&&bk[1]==ck5&&bk[2]*((cx[0]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[0]-cy[1]))*

((cx[0]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[0]-cy[1]))

==(cx[1]*((cx[0]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[0]-cy[1]))-cx[1]*((cx[0]-c

x[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[0]-cy[1]))-(cx[0]-cx[1])*((cx[2]-cx[1])*(cy[3

]-cy[2])-(cx[3]-cx[2])*(cy[2]-cy[1])))*(cx[1]*((cx[0]-cx[1])*(cy[3]-cy[2])-(cx[3]-c

x[2])*(cy[0]-cy[1]))-cx[1]*((cx[0]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[0]-cy[1])

)-(cx[0]-cx[1])*((cx[2]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[2]-cy[1])))+(cy[1]*(

(cx[0]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[0]-cy[1]))-cy[1]*((cx[0]-cx[1])*(cy[3

]-cy[2])-(cx[3]-cx[2])*(cy[0]-cy[1]))-(cy[0]-cy[1])*((cx[2]-cx[1])*(cy[3]-cy[2])-(cx

[3]-cx[2])*(cy[2]-cy[1])))*(cy[1]*((cx[0]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[0]-

cy[1]))-cy[1]*((cx[0]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[0]-cy[1]))-(cy[0]-cy[1

])*((cx[2]-cx[1])*(cy[3]-cy[2])-(cx[3]-cx[2])*(cy[2]-cy[1]))) ){…}

}

Page 7: 2013 NTU-CSIE ACM Rookie Cupb01902011/2013_rookiecup.pdf · 7 2013 NTU-CSIE ACM Rookie Cup Problem C Lolita Counting Time Limit: 10 second Memory limit: 65536 KB "Wow!!" "What a nightmare!",

6

6 2013 NTU-CSIE ACM Rookie Cup

[This page is left empty intentionally.]

Page 8: 2013 NTU-CSIE ACM Rookie Cupb01902011/2013_rookiecup.pdf · 7 2013 NTU-CSIE ACM Rookie Cup Problem C Lolita Counting Time Limit: 10 second Memory limit: 65536 KB "Wow!!" "What a nightmare!",

7

7 2013 NTU-CSIE ACM Rookie Cup

Problem C

Lolita Counting Time Limit: 10 second Memory limit: 65536 KB

"Wow!!"

"What a nightmare!", said LSC. It seems like that LSC really had a very very terrible

dream when he was sleeping!

However, things can always go worse. When LSC woke up, he found himself in a

room that is somehow different from the room he used to sleep. There are so many

doors in the room, which all leads to another room (LSC guesses).

LSC then opens the first door,

"Oh my god!!!", in the room, there are more than a trillion of Lolita!

Then, with a great smile, LSC opens the second door,

"Hollllllllllllllllllllllllllllly!", again, this time, behind the door is even more lolitas.

Feeling so embarrassed, LSC opens the third door, expecting more lolitas.

The third door opens, and lolitas ran out of the door, there are even more lolitas

than LSC had expected!

Smiling, LSC feels like in a paradise. However, there are something that LSC wonder.

"How many lolitas are there in total?"

Counting all lolitas behind the doors must be exhausting. Therefore, LSC decides to

leave the job to you, and he’ll have fun with these lolitas first ^^

Input Description

In the first line, there's an integer ( ), which indicates how many test

cases are there. For each test case, there's an integer ( ) in the first line,

which indicates there are doors. From the second to the line, there's an

integer ( ) in the line, indicating there are lolitas behind

the door.

Output Description

For each test case, output an integer in a single line, indicating how many lolitas are

there in total.

Page 9: 2013 NTU-CSIE ACM Rookie Cupb01902011/2013_rookiecup.pdf · 7 2013 NTU-CSIE ACM Rookie Cup Problem C Lolita Counting Time Limit: 10 second Memory limit: 65536 KB "Wow!!" "What a nightmare!",

8

8 2013 NTU-CSIE ACM Rookie Cup

Sample Input

2

3

2

4

3

2

12345678909876543211234567890987654321

87654321090123456788765432109012345678

Sample Output

9

99999999999999999999999999999999999999

Page 10: 2013 NTU-CSIE ACM Rookie Cupb01902011/2013_rookiecup.pdf · 7 2013 NTU-CSIE ACM Rookie Cup Problem C Lolita Counting Time Limit: 10 second Memory limit: 65536 KB "Wow!!" "What a nightmare!",

9

9 2013 NTU-CSIE ACM Rookie Cup

Problem D

Discovery Time Limit: 1 second Memory limit: 65536 KB

Tower of Saviors has become one of the most popular smart phone game this year.

Everyone addicted to this game has different reason. Take LCS, LIS, and LSC as an

example, LCS is addicted to this game because he likes the background story and music,

whereas LIS likes the balance in the game. LSC, as everyone knows, is a Lolicon. He

updated his FB relationship status "married", and wrote a post, ">//////<" as soon as he

saw some female characters in the game.

After that day, LSC does several deep researches about the world of Tower of

Saviors (especially female characters). The five most attractive female characters are Urd,

Skuld, Verdandi, Idun, and Valkyrie, especially Verdandi. She has the biggest...... sum of

HP, attack and recovery among them. After the research, LSC found that every value in

the game is meticulously calculated and set. Take this five characters as an example, if

you calculate the greatest common divisor and the least common multiple of several

values(HP, attack and recovery) among them, then you will find that there is an

astonishing balance between GCD and LCM!!!

We have no idea how LSC discovered this property. Even if we ask him, he will just

say a weird sentence, "I get immortality by believing in Idun..." Speaking about that there

is a balance between GCD and LCM, LIS, who likes the balance in the game, shows

interest in this astonishing balance after LSC's discovery. He would like to verify whether

LSC's discovery is true or not. However, LIS is not good at mathematics. Can you help

him?

Input Description

There are several test cases (less than 100). For each test case, the first line contains

an integer ( ). The second line contains integers, namely

( ).

Page 11: 2013 NTU-CSIE ACM Rookie Cupb01902011/2013_rookiecup.pdf · 7 2013 NTU-CSIE ACM Rookie Cup Problem C Lolita Counting Time Limit: 10 second Memory limit: 65536 KB "Wow!!" "What a nightmare!",

10

10 2013 NTU-CSIE ACM Rookie Cup

Output Description

For each test case, please output the GCD and LCM of in standard

factorization in two lines. You should print them in strict format: " "

(without quotation), where and are primes. (There must be

space before and after " ", but without space before and after " ", and without extra

space at the end of each line.) Note that if , you should not print " "; if ,

you should output only " " (without quotation) instead of " ". If their GCD or LCM

equals , please output " " (without quotation).

Please print an empty line between two cases (But no extra empty line at the end of

the file).

Sample Input

2

32 6

3

124 8 56

2

25 49

Sample Output

2

2^5 * 3

2^2

2^3 * 7 * 31

1

5^2 * 7^2

Page 12: 2013 NTU-CSIE ACM Rookie Cupb01902011/2013_rookiecup.pdf · 7 2013 NTU-CSIE ACM Rookie Cup Problem C Lolita Counting Time Limit: 10 second Memory limit: 65536 KB "Wow!!" "What a nightmare!",

11

11 2013 NTU-CSIE ACM Rookie Cup

Problem E

The Lolita Sequence Time Limit: 8 second Memory limit: 65536 KB

A "sequence" is a row of ordered items. For example, "2147483647" is a sequence

of 10 decimal integers, and "SongG" is a sequence of 5 English characters.

Upon knowing the definition of sequences, LSC immediately came up with a brand

new idea: the Lolita Sequence! (No one knows what it is; however, it is surely to be

composed of adorable lolitas!) In order to perform further research, LSC turned to his

good friend LCS, who is a master at sequences, and also a Lolicon. However, LCS is

currently dealing with some problems before he is able to help LSC.

Denote the -th element of a integer sequence with length as , where

. We can sum up an interval of the sequence, obtaining a sum

, where . Here’s the problem: given the sequence and a integer ,

how many different intervals are there that sum up to be ?

Since this problem is too easy for LCS, it took about 47.6 seconds for him to write a

program to solve this problem. However, things become complicated when the sequence

is “expanded” into a matrix.

A matrix is a rectangular array of items, arranged in rows and columns. For a

matrix , the item at the -th row and the -th column is denoted as , where

and . Furthermore, a "rectangle" in a matrix is defined by four

integers , where and , and it consists of all

elements where and .

Define a integer matrix "expanded" from a integer sequence with

length as follows: for each , . Similarly, we can sum up a

rectangle of the matrix, obtaining the sum

. Now the problem is, given

the original sequence and a integer , how many different rectangles are there in the

expanded matrix that sum up to be ?

LCS has already prepared a sequence of lolitas as a gift if LSC is capable of solving it.

For both the Lolita Sequence and the sequence of lolitas, LSC had to accept the challenge,

but he has totally no idea. Now it’s your time to help him!

Input Description

The first line contains a single integer ( ), denoting the number of test

cases. For each test case, the integer ( ) and the decimal sequence

Page 13: 2013 NTU-CSIE ACM Rookie Cupb01902011/2013_rookiecup.pdf · 7 2013 NTU-CSIE ACM Rookie Cup Problem C Lolita Counting Time Limit: 10 second Memory limit: 65536 KB "Wow!!" "What a nightmare!",

12

12 2013 NTU-CSIE ACM Rookie Cup

( ) are given in a single line, separated by a single whitespace.

Output Description

For each test case, output a single line containing the answer to the problem.

Sample Input

2

10 12345

16 439873893693495623498263984765

Sample Output

6

40

Page 14: 2013 NTU-CSIE ACM Rookie Cupb01902011/2013_rookiecup.pdf · 7 2013 NTU-CSIE ACM Rookie Cup Problem C Lolita Counting Time Limit: 10 second Memory limit: 65536 KB "Wow!!" "What a nightmare!",

13

13 2013 NTU-CSIE ACM Rookie Cup

Problem F

Lolita Clusters Time Limit: 3 second Memory limit: 65536 KB

One day, LSC feels so happy that he decided to go take some photographs. When he

passes by the park, he found there are so many kids playing in there. Of course, there are

lolitas in the parks playing as well! Therefore, LSC took out his camera and decided to

take some pictures.

However, LSC lacks memory space in his SD card, because it is already filled with

lolitas already! Therefore, he wants to know where he can snap the most lolita, but not

males that are non-lolita.

To make the best use of his limited space, he decided only to take photos of Lolita

clusters. What is lolita clusters? It means lolitas that are gathered together. Let ’s take a

look at the example below:

We can see that there are four clusters of lolitas! LSC can now take pictures of lolitas.

Going to the next park, LSC counts how many lolita clusters there are. But this time, LSC

is lazy, because playing with lolitas last night consumed him too much strength.

Therefore, he decided to ask you for help. LSC tells you to find clusters of Lolita is easy.

"Just find one Lolita first, then start doing something like DFS one Lolita by one

Lolita, then you can get clusters of lolitas!!!! Oh YAAAAAAAAAAAAAA!!!!", said LSC.

Page 15: 2013 NTU-CSIE ACM Rookie Cupb01902011/2013_rookiecup.pdf · 7 2013 NTU-CSIE ACM Rookie Cup Problem C Lolita Counting Time Limit: 10 second Memory limit: 65536 KB "Wow!!" "What a nightmare!",

14

14 2013 NTU-CSIE ACM Rookie Cup

Input Description

In the first line, there is an integer ( ), denoting how many parks are

there (how many time do you have to do the counting for LSC). For each park, there are

two integers , ( ) in one line, which means there are kids in

the park.

Then, there are rows, and for each row, there are numbers. The number

indicates non-lolita male, indicates Lolita!

Output Description

For each park, output an integer in a single line, which means how many Lolita

clusters are there.

Sample Input

2

2 3

100

100

5 6

011011

111010

001110

100101

001110

Sample Output

1

4

Page 16: 2013 NTU-CSIE ACM Rookie Cupb01902011/2013_rookiecup.pdf · 7 2013 NTU-CSIE ACM Rookie Cup Problem C Lolita Counting Time Limit: 10 second Memory limit: 65536 KB "Wow!!" "What a nightmare!",

15

15 2013 NTU-CSIE ACM Rookie Cup

Problem G

The Magic Potion Time Limit: 1 second Memory limit: 65536 KB

LSC has been producing "Magic Potions" for his adorable lolitas. It's claimed that

whoever drinks this white-colored liquid will be able to stay young (under 15y) forever!

However, except LSC, no one knows the exact ingredient of the potion; the only known

fact is that it’s really tiring to produce these potions.

Figure. A bottle of Magic Potion

Today, one of the worst situations has come to LSC and his lolitas: LSC stores all his

potions in a secret warehouse, and now the Child Safety Improving Establishment (CSIE)

has figured out where it is! Upon knowing the situation, LSC asked two of his lolitas,

Sunny and Luna, to help bring all the potions out of the warehouse. However, both

Sunny and Luna are haraguroi lolitas: they both want to take all the potions away so that

only themselves will stay young (again, under 15y) forever and be the only favorite of LSC!

Therefore, after getting to the secret warehouse, they play a game to decide the owner

of the potions, and their future.

There are totally bottles of potions in the warehouse, each bottle is filled with

c.c. of Magic Potions and has a capacity of c.c. ( , both and are

integers) Sunny and Luna take turns choosing a bottle of potion, and then pour all the

potion into another bottle without overflowing it, and then the empty bottle is thrown

away. The game ends when someone is not able to operate as described above, and she

will be the loser. Assume Sunny goes first, and both of them are smart enough to always

play the optimal way, can you predict the final winner of the game?

Input Description

The first line contains a single integer ( ), denoting the number of test

cases. For each test case, the integers ( , ) are

given in a single line, separated by a single whitespace.

Output Description

For each case, output a single line containing the name of the winner ("Sunny" or

"Luna", without quotation).

Page 17: 2013 NTU-CSIE ACM Rookie Cupb01902011/2013_rookiecup.pdf · 7 2013 NTU-CSIE ACM Rookie Cup Problem C Lolita Counting Time Limit: 10 second Memory limit: 65536 KB "Wow!!" "What a nightmare!",

16

16 2013 NTU-CSIE ACM Rookie Cup

Sample Input

2

2 3 5

5 1 4

Sample Output

Luna

Sunny

Page 18: 2013 NTU-CSIE ACM Rookie Cupb01902011/2013_rookiecup.pdf · 7 2013 NTU-CSIE ACM Rookie Cup Problem C Lolita Counting Time Limit: 10 second Memory limit: 65536 KB "Wow!!" "What a nightmare!",

17

17 2013 NTU-CSIE ACM Rookie Cup

Problem H

Rectangle Man Time Limit: 2 second Memory limit: 65536 KB

According to the latest news, the archaeologists have found the monument left

from the aliens called Rectangle Man. They have left a puzzle in the monument. People

who are able to solve the puzzle may found the treasure left behind by the aliens.

The monument says,

"You should know that a rectangle can be determined by four points. But does it

really needs up to four points to determine a rectangle? No! In fact, only two points on

the diagonal are needed.

We have left a map of points. As long as you can determine the maximum number

of rectangles those points can form, you can find the treasure we left.

There is one last thing you should know: we only care about rectangles whose edges

are parallel or perpendicular to the x axis."

The following illustration reveals the only two ways a valid rectangle can be formed:

You can see that two imaginary points and two points selected from the given map

of points are sufficient to form a rectangle.

Note: For a rectangle to be valid, there can be no points inside the boundary of that rectangle.

The following figures illustrates whether a few valid and invalid rectangles.

Your goal is to write a program that utilizes a divide-and-conquer algorithm to solve

the problem and retrieve the treasure left by the aliens.

Page 19: 2013 NTU-CSIE ACM Rookie Cupb01902011/2013_rookiecup.pdf · 7 2013 NTU-CSIE ACM Rookie Cup Problem C Lolita Counting Time Limit: 10 second Memory limit: 65536 KB "Wow!!" "What a nightmare!",

18

18 2013 NTU-CSIE ACM Rookie Cup

=======================================================================

Since LSC is a excellent student of CSIE, of course he studies ADA (Algorithm Design

& Analysis). He is good at problem solving, so every time the homework is released, he

always gets the first blood.

Today, a new piece of homework was released, and the first problem of the

homework is so interesting (the problem description is above) that he decides to share

this problem with his favorite lolita. However, this problem is too difficult for a girl under

15y, so he decides to share the 1D version of the problem: given nodes on a number

line, how many pairs of nodes are there that satisfy that and

that there are no other nodes sitting beween and , i.e.

? ( node p’s coordinate, which is a number.)

Input Description

First line of input is an integer ( ), denoting the number of test cases. For

each test case, the first line will be an integer ( ), denoting the number of

nodes. Then there will be integers in the second line, which are the coordinates of the

nodes separately. Each node’s coordinate will be an integer which can be stored by

long int in C/C++ language.

Output Description

For each test case, output the number of pairs the problem asks in a single line.

Sample Input

2

4

1 2 3 4

5

1 2 3 4 5

Sample Output

3

4

Page 20: 2013 NTU-CSIE ACM Rookie Cupb01902011/2013_rookiecup.pdf · 7 2013 NTU-CSIE ACM Rookie Cup Problem C Lolita Counting Time Limit: 10 second Memory limit: 65536 KB "Wow!!" "What a nightmare!",

19

19 2013 NTU-CSIE ACM Rookie Cup

Problem I

Paper Slip Time Limit: 1 second Memory limit: 65536 KB

Borned in a 3G-era, we use email, cell-phone message, messenger or LINE to deliver

message. However, under some special circumstances, there does exist some traditional

ways to deliver message. The most famous traditional way is passing paper slips to your

classmates in the classroom. LSC likes to use paper slip, but he has his own reason to use

it: he thought that every electronic message is very dangerous since it may eavesdrop by

others. For instance, sometimes LSC discusses lolita and his discovery about five lolitas in

Tower of Saviors with LIS. If they use electronic message, someone may eavesdrop their

conversation and his astonishing discovery will be stolen by others. As a consequence,

LSC chooses to deliver message by passing paper slips because he is able to monitor the

passing process. With a view to avoiding their message being read by others, LSC and his

friends decide to use a special encryption. Now, you've learned that they only modify

English letters by adding a key value on each letter. Others like emotional symbols are

not modified since people always show their expression on their face directly.

One day, you steal a paper slip from LSC, and you are curious about what is written

in that paper slip, so what you want to do is to decrypt the message. Perhaps you may

find out how LSC discovers the property of five lolitas in Tower of Saviors by decrypting

the message XDrz.

"It is important to notice which number is the prime.", said LSC.

Input Description

There are several test cases. For each test case, there is a sentence in one line (the

number of characters ), which are encrypted by LSC.

Output Description

For each test case, please decrypt the sentence and output it in a single line. Note:

for instance, if you add to 'z', it will no longer be an English letter. In this case, you

must minus after adding to it. Thus, it should be 'e'.

Sample Input

Una Una J 7122 rirel frpbaq.

Fuv-Na <3 Gvna-Lv ^_^.

Yafhla vf ubarl >////////<

YFP ybirf ybyvgn

Neovgre Lnat vf "zvqqyr gjb".

Page 21: 2013 NTU-CSIE ACM Rookie Cupb01902011/2013_rookiecup.pdf · 7 2013 NTU-CSIE ACM Rookie Cup Problem C Lolita Counting Time Limit: 10 second Memory limit: 65536 KB "Wow!!" "What a nightmare!",

20

20 2013 NTU-CSIE ACM Rookie Cup

Sample Output

Han Han W 7122 every second.

Shi-An <3 Tian-Yi ^_^.

Lnsuyn is honey >////////<

LSC loves lolita

Arbiter Yang is "middle two".

Page 22: 2013 NTU-CSIE ACM Rookie Cupb01902011/2013_rookiecup.pdf · 7 2013 NTU-CSIE ACM Rookie Cup Problem C Lolita Counting Time Limit: 10 second Memory limit: 65536 KB "Wow!!" "What a nightmare!",

21

21 2013 NTU-CSIE ACM Rookie Cup

Problem J

LSC Wants to See Cute Girls Time Limit: 3 second Memory limit: 65536 KB

LSC is riding a bicycle along a straight road. In the meantime, he sees two cute girls,

we name them A and B. As a Lolicon, LSC wants to see the two girls at the same time, but

he finds out that the angle of view varies while he moves. If the angle is too large, he will

not be able to see them simultaneously. Assume that LSC is riding his bicycle on the X

axis from far left to far right, the two cute girls are in the position and

, and LSC is at . You can observe that the angle changes as

moves on the X axis. Please find the point which has the maximum angle for

LSC, so that he can know whether he can see the two girls all the time in his way.

It is guaranteed that the two girls are not in the same position, and will not be on

the X axis. Also note that the angle we are discussing in this problem is between 0 degree

to 180 degree. For example, a right angle is 90 degree but not 270 degree. You may

argue that LSC will have to look backwards while riding a bicycle, but as an "ultimate

Lolicon", LSC has already learned this skill, so you don't have to worry about it.

Input Description

The first line contains an integer ( ), which is the number of test

cases. For each test case, there are 4 integers ( ;

; ) in one line.

Output Description

For each test case, output the x coordinate of in a single line. If there are more

than one possible point that can maximize the angle , choose the one that has the

largest x coordinate. Any answer with relative or absolute error within will be

accepted.

Sample Input

4

1 1 2 1

-1 1 -1 2

1 2 3 4

1 2 3 -4

Page 23: 2013 NTU-CSIE ACM Rookie Cupb01902011/2013_rookiecup.pdf · 7 2013 NTU-CSIE ACM Rookie Cup Problem C Lolita Counting Time Limit: 10 second Memory limit: 65536 KB "Wow!!" "What a nightmare!",

22

22 2013 NTU-CSIE ACM Rookie Cup

Sample Output

1.500000000

0.414213562

3.000000000

1.666666667