4tocontest

6

Click here to load reader

Upload: berthin

Post on 04-Jul-2015

272 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 4tocontest

IV CusContest - Ingeniería Informática y de Sistemas – UNSAAC 2012 1

“4to CusContest”

Universidad Nacional de San Antonio Abad del Cusco

Carrera Profesional de Ingeniería Informática y de Sistemas

“Problem Set”Lunes 15 de Octubre del 2012

Este conjunto de problemas contiene 5 problemas

Organizado por: ACM Chapter Cusco y DAI-UNSAAC

CUSCO-PERU

Page 2: 4tocontest

IV CusContest - Ingeniería Informática y de Sistemas – UNSAAC 2012 2

A.Counting Triangles[TRICOUNT]

We define the LEVEL of a triangle as in the following illustrative image:

Task: Your task is very easy. All you have to do is to count all triangles in the biggest one (Level N).

Input

The first line of the input contains an integer T (T ≤ 10000) - the number of test cases and T lines follow. Each line contains an integer N (1 ≤ N ≤ 106) which is the level of the triangle in that test case.

Output

For each test case, you should write a separate line: the number of triangles in the biggest one (Level N). (All answers will fit within the range of a 64-bit integer. Use : long long (C/C++), long (JAVA), Int64(PASCAL), long(C#))

ExampleInput:3123

Output:1513

B. Reliable Nets [RELINETS]You’re in charge of designing a campus network between buildings and are very worried about its reliability and its cost. So, you’ve decided to build some redundancy into your network while keeping it as inexpensive as possible. Specifically, you want to build the cheapest network so that if any one line is broken, all buildings can still communicate. We’ll call this a minimal reliable net.

Input

There will be multiple test cases for this problem. Each test case will start with a pair of integers n (<=15) and m (<= 20) on a line indicating the number of buildings (numbered 1 through n) and the number of potential inter-building connections, respectively. (Values of n = m = 0 indicate the end

Page 3: 4tocontest

IV CusContest - Ingeniería Informática y de Sistemas – UNSAAC 2012 3

of the problem.) The following m lines are of the form b1 b2 c (all positive integers) indicating that

it costs c to connect building b1 and b2. All connections are bidirectional.

Output

For each test case you should print one line giving the cost of a minimal reliable net. If there is a minimal reliable net, the output line should be of the form:

The minimal cost for test case p is c.

where p is the number of the test case (starting at 1) and c is the cost. If there is no reliable net possible, output a line of the form:

There is no reliable net possible for test case p.

ExampleInput:4 51 2 11 3 22 4 23 4 12 3 12 11 2 50 0

Output:The minimal cost for test case 1 is 6.There is no reliable net possible for test case 2.

C.Integral Maximization[INTEGMAX]

A set of points on the XY plane, all of them with different x coordinate, defines a polygonalline in the following way: sort the points in increasing order of their x coordinates, and connecteach point with its neighbors. The integral of such polygonal line is the area contained belowthe line and above the x axis, between the first and last values of x. For instance, the set ofpoints {(5, 1), (3, 2), (6, 2), (2, 1)} defines the polygonal line shown in the figure; the integral ofthe polygonal line is the shaded area, with a value of 6.

Given a set of N different values for x, and a set of N values for y, we want to pair them toform N points on the plane such that the integral of the polygonal line defined by the points isas large as possible.

Input

The input contains several test cases, each one described in exactly three lines. The first line of

Page 4: 4tocontest

IV CusContest - Ingeniería Informática y de Sistemas – UNSAAC 2012 4

each test case contains an integer N indicating the number of points in the set (2 ≤ N ≤ 104 ).The second line contains N different integers Xi separated by single spaces (1 ≤ Xi ≤ 104

for 1 ≤ i ≤ N ); these integers represent the values of x and are given in increasing order(Xi < Xi+1 for 1 ≤ i ≤ N − 1). The third line contains N integers Yi separated by single spaces(1 ≤ Yi ≤ 104 for 1 ≤ i ≤ N ); these integers represent the values of y and are not given in anyparticular order. The last line of the input contains a single −1 and should not be processedas a test case.

Output

For each test case output a single line with the maximum integral of a polygonal line formedby pairing the input values, using exactly one decimal digit. Notice that one decimal digit isalways enough to represent the exact value of the integral of a polygonal line defined by pointswith integer coordinates.

ExampleInput:21 21 242 3 5 61 2 1 2-1

Output:1.57.0

D. Chocolate [CHOCOLA]We are given a bar of chocolate composed of m*n square pieces. One should break the chocolate into single squares. Parts of the chocolate may be broken along the vertical and horizontal lines as indicated by the broken lines in the picture.

A single break of a part of the chocolate along a chosen vertical or horizontal line divides that part into two smaller ones. Each break of a part of the chocolate is charged a cost expressed by a positive integer. This cost does not depend on the size of the part that is being broken but only depends on the line the break goes along. Let us denote the costs of breaking along consecutive vertical lines with x1, x2, ..., xm-1 and along horizontal lines with y1, y2, ..., yn-1.

The cost of breaking the whole bar into single squares is the sum of the successive breaks. One should compute the minimal cost of breaking the whole chocolate into single squares.

For example, if we break the chocolate presented in the picture first along the horizontal lines, and

Page 5: 4tocontest

IV CusContest - Ingeniería Informática y de Sistemas – UNSAAC 2012 5

next each obtained part along vertical lines then the cost of that breaking will be y1+y2+y3+4*(x1+x2+x3+x4+x5).

Task

Write a program that for each test case:

• Reads the numbers x1, x2, ..., xm-1 and y1, y2, ..., yn-1

• Computes the minimal cost of breaking the whole chocolate into single squares, writes the result.

Input

One integer in the first line, stating the number of test cases, followed by a blank line. There will be not more than 20 tests.

For each test case, at the first line there are two positive integers m and n separated by a single space, 2 <= m,n <= 1000. In the successive m-1 lines there are numbers x1, x2, ..., xm-1, one per line,

1 <= xi <= 1000. In the successive n-1 lines there are numbers y1, y2, ..., yn-1, one per line, 1 <= yi

<= 1000.

The test cases will be separated by a single blank line.

Output

For each test case : write one integer - the minimal cost of breaking the whole chocolate into single squares.

ExampleInput:1

6 421314412

Output:42

E.What’s Next [ACPC10A]

According to Wikipedia, an arithmetic progression (AP) is a sequence of numbers such that the difference of any two successive members of the sequence is a constant. For instance, the sequence 3, 5, 7, 9, 11, 13, . . . is an arithmetic progression with common difference 2. For this problem, we will limit ourselves to arithmetic progression whose common difference is a non-zero integer.On the other hand, a geometric progression (GP) is a sequence of numbers where each term after the first is found by multiplying the previous one by a fixed non-zero number called the common ratio. For example, the sequence 2, 6, 18, 54, . . . is a geometric progression with common ratio 3. For this problem, we will limit ourselves to geometric progression whose common ratio is a non-zero integer.

Page 6: 4tocontest

IV CusContest - Ingeniería Informática y de Sistemas – UNSAAC 2012 6

Given three successive members of a sequence, you need to determine the type of the progression and the next successive member.

Input

Your program will be tested on one or more test cases. Each case is specified on a single line with three integers (−10, 000 < a1 , a2 , a3 < 10, 000) where a1 , a2 , and a3 are distinct.The last case is followed by a line with three zeros.

Output

For each test case, you program must print a single line of the form:XX vwhere XX is either AP or GP depending if the given progression is an Arithmetic or Geometric Progression. v is the next member of the given sequence. All input cases are guaranteed to be either an arithmetic or geometric progressions.

ExampleInput:4 7 102 6 180 0 0

Output:AP 13GP 54