0% found this document useful (0 votes)
35 views6 pages

Facultad de Ingeniería UMSA Programming C++ Courseware 1.0 Problem Set

This document contains 3 programming problems and their descriptions: Problem A involves calculating the number of sodas Tim can drink given the number of empty bottles he starts with, finds, and needs to exchange for a new soda. Problem B involves counting the number of duplicate ticket numbers in a collection of tickets from a school party, where some tickets may have been illegally duplicated. Problem C describes a game where N students are eliminated in rounds based on a formula until one winner remains, and involves determining the winner for each test case.

Uploaded by

sagrados1
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views6 pages

Facultad de Ingeniería UMSA Programming C++ Courseware 1.0 Problem Set

This document contains 3 programming problems and their descriptions: Problem A involves calculating the number of sodas Tim can drink given the number of empty bottles he starts with, finds, and needs to exchange for a new soda. Problem B involves counting the number of duplicate ticket numbers in a collection of tickets from a school party, where some tickets may have been illegally duplicated. Problem C describes a game where N students are eliminated in rounds based on a formula until one winner remains, and involves determining the winner for each test case.

Uploaded by

sagrados1
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Facultad de Ingeniera UMSA Programming C++ Courseware 1.

0 Problem Set
Recopilado por: Jhon Rogers Aquize Gutierrez Hugo Orlando Condori Quispe July 9, 2011

Programming Open Courseware

FACULTAD DE INGENIERA

Problem A Soda Surpler


Source le name:soda.cpp or soda.java

Tim is an absolutely obsessive soda drinker, he simply cannot get enough. Most annoyingly though, he almost never has any money, so his only obvious legal way to obtain more soda is to take the money he gets when he recycles empty soda bottles to buy new ones. In addition to the empty bottles resulting from his own consumption he sometimes nd empty bottles in the street. One day he was extra thirsty, so he actually drank sodas until he couldnt afford a new one. Input Three non-negative integers e, f, c, where e 1000 equals the number of empty soda bottles in Tims possession at the start of the day, f 1000 the number of empty soda bottles found during the day, and 1 c 2000 the number of empty bottles required to buy a new soda. The end of the input is indicated by a line containing only three zeros, separated by blank spaces. Output How many sodas did Tim drink on his extra thirsty day?

Sample input

Sample output

9 0 3 5 5 2

4 9

P.P. Hugo Orlando Condori Quispe

Programming Open Courseware

FACULTAD DE INGENIERA

Problem B Fake tickets


Source le name:fake.cpp or fake.java

Your school organized a big party to celebrate your team brilliant win in the prestigious, worldfamous ICPC (International Collegiate Poetry Contest). Everyone in your school was invited for an evening which included cocktail, dinner and a session where your team work was read to the audience. The evening was a success many more people than you expected showed interested in your poetry although some critics of yours said it was food rather than words that attracted such an audience. Whatever the reason, the next day you found out why the school hall had seemed so full: the school director conded he had discovered that several of the tickets used by the guests were fake. The real tickets were numbered sequentially from 1 to N (N 10000). The director suspects some people had used the school scanner and printer from the Computer Room to produce copies of the real tickets. The director gave you a pack with all tickets collected from the guests at the partys entrance, and asked you to determine how many tickets in the pack had clones, that is, another ticket with the same sequence number. Input The input contains data for several test cases. Each test case has two lines. The rst line contains two integers N and M which indicate respectively the number of original tickets and the number of persons attending the party (1 N 10000 and 1 M 20000). The second line of a test case contains M integers Ti representing the ticket numbers in the pack the director gave you (1 Ti N). The end of input is indicated by N = M = 0. 1
P.P. Hugo Orlando Condori Quispe

Programming Open Courseware

FACULTAD DE INGENIERA

Output For each test case your program should print one line, containing the number of tickets in the pack that had another ticket with the same sequence number.

Sample input

Sample output

5 5 3 3 1 2 4 6 10 6 1 3 6 6 4 2 3 1 2 0 0

1 4

P.P. Hugo Orlando Condori Quispe

Programming Open Courseware

FACULTAD DE INGENIERA

Problem C Game
Source le name:game.cpp or game.java

A group of N MIT students decide to play the following intelligent game. They rst choose three numbers A, B, and P , and then they gather together in a circle. Each MIT student wears a t-shirt with a distinct number from 1 to N on it. The students arrange themselves in a circle so that the numbers on their t-shirts are in consecutive order. The game has N count-and-eliminate rounds, starting with round 1. In round i, the (1 + ((Ai + B) mod P ))-th student is eliminated from the circle, with the counting starting from the student with the smallest number on his/her t-shirt. The last student to be eliminated from the circle is the winner of the game. Input There will be several test cases, each describing an instance of a game. Each test case has a single line containing four numbers, N , A, B, and P (1 N, P 5000, 0 A, B 5000). The input data is terminated by a line containing four zeroes, and should not be processed. Output For each test case, output the winner of the game, as in the sample output.

P.P. Hugo Orlando Condori Quispe

Programming Open Courseware

FACULTAD DE INGENIERA

Sample input

Sample output

3 1 2 5 4 3 5 2 0 0 0 0

The winner is 3. The winner is 4.

P.P. Hugo Orlando Condori Quispe

You might also like