荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: kaman (天外飞仙), 信区: ACMICPC
标  题: 贴几道简单的题FROM USACOGATE
发信站: 荔园晨风BBS站 (Tue Mar 23 10:40:09 2004), 站内信件

                        1.  Your Ride Is Here
It is a well-known fact that behind every good comet is a UFO. These UFOs
often come to collect loyal supporters from here on Earth. Unfortunately,
they only have room to pick up one group of followers on each trip. They do,
 however, let the groups know ahead of time which will be picked up for each
 comet by a clever scheme: they pick a name for the comet which, along
with the name of the group, can be used to determine if it is a particular
group's turn to go (who do you think names the comets?). The details of
the matching scheme are given below; your job is to write a program which
takes the names of a group and a comet and then determines whether the group
 should go with the UFO behind that comet.

Both the name of the group and the name of the comet are converted into a
number in the following manner: the final number is just the product of
all the letters in the name, where "A" is 1 and "Z" is 26. For instance, the
 group "USACO" would be 21 * 19 * 1 * 3 * 15 = 17955. If the group's
number mod 47 is the same as the comet's number mod 47, then you need to
tell the group to get ready! (Remember that "a mod b" is the remainder
left over after dividing a by b; 34 mod 10 is 4.)

Write a program which reads in the name of the comet and the name of the
group and figures out whether according to the above scheme the names are
a match, printing "GO" if they match and "STAY" if not. The names of the
groups and the comets will be a string of capital letters with no spaces
or punctuation, up to 6 characters long.

Examples:

Input  Output
COMETQ
HVNGAT

 GO
ABSTAR
USACO
 STAY


PROGRAM NAME: ride
INPUT FORMAT
Line 1:  An upper case character string of length 1..6 that is the name of
the comet.
Line 2:  An upper case character string of length 1..6 that is the name of
the group.

NOTE: The input file has a newline at the end of each line but does not have
 a "return". Sometimes, programmers code for the Windows paradigm of
"newline" followed by "return"; don't do that! Use simple input routines
like "readln" (for Pascal) and, for C/C++, "fscanf" and "fid>>string".

SAMPLE INPUT (file ride.in)
COMETQ
HVNGAT

OUTPUT FORMAT
A single line containing either the word "GO" or the word "STAY".
SAMPLE OUTPUT (file ride.out)
GO

--------------------------------------------------------------------
                           2. Greedy Gift Givers
You are to determine, for a group of gift-giving friends, how much more each
 person gives than they receive (and vice versa for those who view gift
giving with cynicism). In this problem, each person sets aside some money
for gift-giving and divides this money evenly among all those to whom
gifts are given. However, in any group of friends, some people are more
giving than others (or at least may have more acquaintances) and some people
 have more money than others.

Given a group of friends, no one of whom has a name longer than 14
characters, the money each person in the group spends on gifts, and a
(sub)list of friends to whom each person gives gifts, determine how much
more (or less) each person in the group gives than they receive.

IMPORTANT NOTE
The grader machine is a Linux machine that uses standard Unix conventions:
end of line is a single character often known as '\n'. This differs from
Windows, which ends lines with two charcters, '\n' and '\r'. Do not let your
 program get trapped by this!

PROGRAM NAME: gift1
INPUT FORMAT
The input is a group of gift-givers which consists of several lines: Line 1:
  The number of people in the group, 2 <= NP <= 10
Lines 2..NP+1:  NP names of the people in the group, one per line
Lines NP+2..end:  NP groups of lines organized like this: The first line
in the group tells the person's name who will be giving gifts.
The second line in the group contains two numbers: The initial amount of
money (in the range 0..2000) spent on gifts by the giver and then the number
 of people to whom the giver will give gifts, NGi (0 <= NGi <= NP-1).
If NGi is nonzero, each of the next NGi lines lists the the name of a
recipient of a gift.




SAMPLE INPUT (file gift1.in)
5
dave
laura
owen
vick
amr
dave
200 3
laura
owen
vick
owen
500 1
dave
amr
150 2
vick
owen
laura
0 2
amr
vick
vick
0 0

OUTPUT FORMAT
The output is NP lines, each with the name of a person followed by a
single blank followed by the net gain or loss (final_money_value -
initial_money_value) for that person. The names should be printed in the
same order they appear on line 2 of the input.

All gifts are integers. Each person gives the same integer amount of money
to each friend to whom any money is given, and gives as much as possible
that meets this constraint. Any money not given is kept by the giver.

SAMPLE OUTPUT (file gift1.out)
dave 302
laura 66
owen -359
vick 141
amr -150

------------------------------------------------------------------
                      3.Broken Necklace
You have a necklace of N red, white, or blue beads (3<=N<=350) some of which
 are red, others blue, and others white, arranged at random. Here are two
examples for n=29:

                1 2                               1 2
            r b b r                           b r r b
          r         b                       b         b
         r           r                     b           r
        r             r                   @             r
       b               r                 @               @
      b                 b               r                 r
      b                 b               b                 b
      b                 b               r                 b
       r               r                 b               r
        b             r                   r             r
         b           r                     r           r
           r       r                         r       b
             r b r                             r r @
            Figure A                         Figure B
                        r red bead
                        b blue bead
                        @ white bead

The beads considered first and second in the text that follows have been
marked in the picture.

The configuration in Figure A may be represented as a string of b's and r's,
 where b represents a blue bead and r represents a red one, as follows:
brbrrrbbbrrrrrbrrbbrbbbbrrrrb .

Suppose you are to break the necklace at some point, lay it out straight,
and then collect beads of the same color from one end until you reach a bead
 of a different color, and do the same for the other end (which might not be
 of the same color as the beads collected before this).

Determine the point where the necklace should be broken so that the most
number of beads can be collected.

Example
For example, for the necklace in Figure A, 8 beads can be collected, with
the breaking point either between bead 9 and bead 10 or else between bead 24
 and bead 25.

In some necklaces, white beads had been included as shown in Figure B above.
 When collecting beads, a white bead that is encountered may be treated as
either red or blue and then painted with the desired color. The string
that represents this configuration will include the three symbols r, b and
w.

Write a program to determine the largest number of beads that can be
collected from a supplied necklace.

PROGRAM NAME: beads
INPUT FORMAT
Line 1:  N, the number of beads
Line 2:  a string of N characters, each of which is r, b, or w

SAMPLE INPUT (file beads.in)
29
wwwbbrwrbrbrrbrbrwrwwrbwrwrrb

OUTPUT FORMAT
A single line containing the maximum of number of beads that can be
collected from the supplied necklace.
SAMPLE OUTPUT (file beads.out)
11
--------------------------------------------------------

                        4.Prime Palindromes
The number 151 is a prime palindrome because it is both a prime number and a
 palindrome (it is the same number when read forward as backward). Write a
program that finds all prime palindromes in the range of two supplied
numbers a and b (5 <= a < b <= 100,000,000); both a and b are considered
to be within the range .

PROGRAM NAME: pprime
INPUT FORMAT
Line 1:  Two integers, a and b

SAMPLE INPUT (file pprime.in)
5 500

OUTPUT FORMAT
The list of palindromic primes in numerical order, one per line.
SAMPLE OUTPUT (file pprime.out)
5
7
11
101
131
151
181
191
313
353
373
383


-----------------------------------------------------
****来自USACOGATE的SECTION 1,比较简单,需要答案或测试数据的请回贴。


--
Long long ago,there is a hero stand at the edge of the land.......

     ▁▁
   ▕天外▏
   ▕飞仙▏
     ▔▔

※ 来源:·荔园晨风BBS站 bbs.szu.edu.cn·[FROM: 192.168.111.157]


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店