uva814

maksyuki 发表于 oj 分类,标签: ,
0

For an electronic mail application you are to describe the SMTP-based communication that takes place between pairs of MTAs. The sender’s User Agent gives a formatted message to the sending Message Transfer Agent (MTA). The sending MTA communicates with the receiving MTA using the Simple Mail Transfer Protocol (SMTP). The receiving MTA delivers mail to the receiver’s User Agent. After a communication link is initialized, the sending MTA transmits command lines, one at a time, to the receiving MTA, which returns a three-digit coded response after each command is processed. The sender commands are shown below in the order sent for each message. There is more than one RCPT TO line when the same message is sent to several users at the same MTA. A message to users at different MTAs requires separate SMTP sessions.

HELO myname Identifies the sender to the receiver (yes, there is only one L)

MAIL FROM:< sender > Identifies the message sender

RCPT TO:< user > Identifies one recipient of the message

DATA Followed by an arbitrary number of lines of text comprising the message body, ending with a line containing a period in column one.

QUIT Terminates the communication.

The following response codes are sent by the receiving MTA:

221 Closing connection (after QUIT)

250 Action was okay (after MAIL FROM and RCPT TO specifying an acceptable user, or completion of a message)

354 Start sending mail (after DATA)

550 Action not taken; no such user here (after RCPT TO with unknown user)

Input

The input contains descriptions of MTAs followed by an arbitrary number of messages. Each MTA description begins with the MTA designation and its name (1 to 15 alphanumeric characters). Following the MTA name is the number of users that receive mail at that MTA and a list of the users (1 to 15 alphanumeric characters each). The MTA description is terminated by an asterisk in column 1. Each message begins with the sending user’s name and is followed by a list of recipient identifiers. Each identifier has the form user@mtaname. The message (each line containing no more than 72 characters) begins and terminates with an asterisk in column 1. A line with an asterisk in column 1 instead of a sender and recipient list indicates the end of the entire input.

Output

For each message, show the communication between the sending and receiving MTAs. Every MTA mentioned in a message is a valid MTA; however, message recipients may not exist at the destination MTA. The receiving MTA rejects mail for those users by responding to the RCPT TO command with the 550 code. A rejection will not affect delivery to authorized users at the same MTA. If there is not at least one authorized recipient at a particular MTA, the DATA is not sent. Only one SMTP session is used to send a message to users at a particular MTA. For example, a message to 5 users at the same MTA will have only one SMTP session. Also a message is addressed to the same user only once. The order in which receiving MTAs are contacted by the sender is the same as in the input file. As shown in the sample output, prefix the communication with the communicating MTA names, and indent each non-empty communication line. No innecessary spaces should be printed.

Sample Input

MTA London 4 Fiona Paul Heather Nevil
MTA SanFrancisco 3 Mario Luigi Shariff
MTA Paris 3 Jacque Suzanne Maurice
MTA HongKong 3 Chen Jeng Hee
MTA MexicoCity 4 Conrado Estella Eva Raul
MTA Cairo 3 Hamdy Tarik Misa
*
Hamdy@Cairo Conrado@MexicoCity Shariff@SanFrancisco Lisa@MexicoCity
*
Congratulations on your efforts !!
--Hamdy
*
Fiona@London Chen@HongKong Natasha@Paris
*
Thanks for the report! --Fiona
*
*
Sample Output

Connection between Cairo and MexicoCity
HELO Cairo
250
MAIL FROM:<Hamdy@Cairo>
250
RCPT TO:<Conrado@MexicoCity>
250
RCPT TO:<Lisa@MexicoCity>
550
DATA
354
Congratulations on your efforts !!
--Hamdy
.
250
QUIT
221
Connection between Cairo and SanFrancisco
HELO Cairo
250
MAIL FROM:<Hamdy@Cairo>
250
RCPT TO:<Shariff@SanFrancisco>
250
DATA
354
Congratulations on your efforts !!
--Hamdy
.
250
QUIT
221
Connection between London and HongKong
HELO London
250
MAIL FROM:<Fiona@London>
250
RCPT TO:<Chen@HongKong>
250
DATA
354
Thanks for the report! --Fiona
.
250
QUIT
221
Connection between London and Paris
HELO London
250
MAIL FROM:<Fiona@London>
250
RCPT TO:<Natasha@Paris>
550
QUIT
221

 

题目类型:简单字符处理+模拟

算法分析:按照题目给定的过程模拟MTA交互即可,注意若接受者中有重复的地址是需要去除掉的

 

uva207

maksyuki 发表于 oj 分类,标签:
0

A PGA (Professional Golf Association) Tour event is a golf tournament in which prize money is awarded to the best players. The tournament is broken into four rounds of 18 holes apiece. All players are eligible to play the first two rounds. Only those with the best scores from those 36 holes “make the first cut” to play the final two rounds and qualify for prize money. Players with the best 72-hole aggregate scores (the lowest scores) earn prize money.

You must write a program to determine how the total prize money (called the tournament “purse”) is to be allocated for a tournament.

Specifications are as follows.

1) All players will play at least two 18-hole rounds (36 holes in all) unless they are disqualified for some reason.

2) Any player who is disqualified stops playing at the time of the disqualification. Players who are disqualified during the first two rounds are ineligible to make the cut. Players who are disqualified during either of the last two rounds are ineligible to win prize money.

3) At the end of the first two rounds, the field of players is cut to the 70 players with the lowest 36-hole scores plus ties. So if 10 players are tied for 70th place, then 79 players make the 36-hole cut. Players who do not make the 36-hole cut are eliminated from the playing field and do not win any prize money.

4) The players who do make the 36-hole cut play an additional 36 holes (two 18-hole rounds) and are paid a percentage of the total prize money depending on their 72-hole aggregate score. The lower the score, the more prize money a player wins.

5) Players are paid percentages of the the tournament purse according to their final standings. For example, if the tournament purse were $1,000,000 and the winner’s share were 18%, the winner would earn $180,000.

6) There will be only one winner of this tournament. (In an actual golf tournament, when there is a tie for the low 72-hole score, there is be a play-off among the tied players. We will ignore that situation.) 7) There may be a tie for any or all of the positions between 2 and 70. If there is a tie among n players for position k, the money designated for positions k through n + k − 1 is pooled and allocated equally among the tied players. For example, using the sample data given later, if there were a tie for second place between two golfers, they would each win $88,000 [(10.8% + 6.8%)/2 = 8.8% * $1,000,000]. If there were a three-way tie, all three golfers would get $74,666.67 [(10.8% + 6.8% + 4.8%)/3 = 7.466667% * $1,000,000]. The extra penny is ignored.

8) If disqualification reduces the field to less than 70 players, the money for the last and any other places not covered is not allocated. For example, if exactly 70 players make the cut but three of them are disqualified, then the tournament simply pays 67 places.

9) Amateur golfers may play in professional tournaments but can win no money. Any prize money “won” by an amateur is allocated to the next lower position. For example, if an amateur has placed third in a tournament, then third place money goes to the fourth place finisher, and fourth place money goes to the fifth place finisher, etc.

10) Only the low 70 non-amateur places and ties earn prize money. For example, if 75 players make the 36-hole cut, it is possible for 5 of them not to earn prize money, assuming none of the players making the cut are amateurs.

Input

The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.

The input for each case is broken into two segments. The amount of the tournament purse and the percentages for all the 70 places are stored in the first segment of the input. This segment contains exactly 71 lines, which are formatted as follows.

Line 1: Total value of the purse

Line 2: Percentage of the purse designated for first place

Line 3: Percentage of the purse designated for second place

...

Line71: Percentage of the purse designated for 70-th place All entries in the first 71 file lines can be read as real numbers.

All percentages are given to four decimal places. Assume the percentages are correct and sum to 100%.

A partial example of the first segment of the input file is shown in the sample input section below.

The second segment of the input contains the players’ names and their respective scores for the four rounds. There is a maximum of 144 players.A first line contains the number of players and then one more line for each one of them, with the format as follows (see a partial example in the sample input section).

Characters 1–20: Player name

Characters 21–23: Round 1 score (first 18 holes)

Characters 24–26: Round 2 score (second 18 holes)

Characters 27–29: Round 3 score (third 18 holes)

Characters 30–32: Round 4 score (fourth 18 holes)

Any player who has an asterisk ‘*’ at the end of his last name is an amateur. All players who are not disqualified will have four 18-hole scores listed. (Even though in an actual tournament, players who do not make the cut do not get to play the last two rounds of the tournament, for the purposes of this program all players who are not disqualified will have four 18-hole scores listed.) A player who is disqualified during a round will have a score on that round shown as ‘DQ’. That player will have no additional scores for the tournament. Assume that at least 70 players will make the 36-hole cut. The end of input is denoted by end-of-file.

Output

For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.

Output from this program consists of names of all players who made the 36-hole cut, their finish positions (with the letter ‘T’ after the numeric value representing the finish position if there is a tie for that position, that means two or more NON-AMATEUR players with the same score, and all of them earning money), scores for each round, total scores, and the amounts of money won. Print the money won by a player only if the player gets a prize (even if the prize is $0.00). Disqualified players are listed at the bottom with scores of ‘DQ’ placed in the ‘TOTAL’ column; the order among disqualified players is unimportant. No player who failed to make the 36-hole cut is listed in the output.

Each column of output should be formatted and labelled appropriately. The dollar amounts should be correct to two decimal places.

In case of tie order the players by rounds completed and by total shots. If there’s still a tie, order them in alphabetical order.

A partial example of the output file (not corresponding to the sample input) is show in the sample output section.

Note

Be careful about ties: an amateur player should not have a ‘T’ since it doesn’t earn money. Only if two or more players earn money and they have the same points, they should have a ‘T’.

Sample Input

1
1000000.00
18.0000
10.8000
6.8000
4.8000
...
0.2020
0.2000
140
WALLY WEDGE 70 70 70 70
SANDY LIE 80 DQ
SID SHANKER* 90 99 62 61
...
JIMMY ABLE 69 73 80 DQ

Sample Output

Player Name Place RDJ RD2 RD3 RD4 TOTAL Money Won
-----------------------------------------------------------------------
WALLY WEDGE 1 70 70 70 70 280 $180000.00
HENRY HACKER 2T 77 70 70 70 287 $ 88000.00
TOMMY TWO IRON 2T 71 72 72 72 287 $ 88000.00
BEN BIRDIE 4 70 74 72 72 288 $ 48000.00
NORMAN NIBLICK* 4 72 72 72 72 288
...
LEE THREE WINES 71 99 99 99 98 395 $ 2000.00
JOHNY MELAVO 72 99 99 99 99 396
JIMMY ABLE 69 73 80 DQ
EDDIE EAGLE 71 71 DQ

 

题目类型:暴力枚举

算法分析:按照题目要求模拟即可