Skip to main content

Posts

Showing posts with the label AD-HOC

URI Problem 2455 Solution Gangorra - URI Online Judge Solution

URI Online Judge Solution 2455 Gangorra Using Python Programming Language. Joãozinho has just changed schools and the first thing he noticed at the new school is that the seesaw of the playground is not symmetrical, one end is longer than the other. After playing a few times with a friend of the same weight, he realized that when he is at one end, the seesaw unbalances towards his side (that is, he is at the bottom, and the friend at the top), they switch sides, the seesaw is unbalanced towards the friend's side. Without understanding the situation, Joãozinho asked for help from another friend from another series, who explained that the length of the side interferes with the balance of the seesaw, as the seesaw will be balanced when P 1 ∗ C 1 = P 2 ∗ C 2 where P 1 and P 2 are the child's weights on the left and right side, respectively, and C 1 and C 2 are the lengths of the seesaw on the left and right side, respectively. Input The first and only line of the entry contains 4 i...

URI Problem 2454 Solution Flipper - URI Online Judge Solution

URI Online Judge Solution 2454 Flipper Using Python Programming Language. Flipper is a type of game where a metal ball falls through a maze of paths until it reaches the bottom of the maze. The amount of points the player earns depends on the path the ball takes. The player can control the path of the ball by changing the position of some small doors in the maze. Each small door can be in position 0, which means facing left, or in position 1, which means facing right. Consider the flipper in the figure below, which has two small doors. Door P is in position 1 and door R is in position 0. This way, the ball will fall down path B. You must write a program that, given the positions of the doors P and R, on this flipper in the figure, tell which of the three paths, A, B or C, the ball will fall! Input The entrance consists of only one line containing two numbers P (0 or 1) and R (0 or 1), indicating the positions of the two flaps on the figure flipper. Output The output of your program sho...

URI Problem 2413 Solution Internet search- URI Online Judge Solution

URI Online Judge Solution 2413 Internet search Using Python Programming Language. João did a search on his favorite search site, and found the answer he was looking for in the third link listed. In addition, he saw on the website that people had clicked on this link before. João had previously read, also on the Internet, that the number of people who click on the second link listed is double the number of people who click on the third link listed. In that reading, he also found that the number of people who click on the second link is half the number of people who click on the first link. João is intrigued to find out how many people clicked on the first link in the search, and since you are a friend of his, you want his help in this task. Input Each test case has only one number, t (1 ≤ t ≤ 1000), which represents the number of people who clicked on the third search link. Output For each test case, print only one line, containing only one integer, indicating how many people clicked on...

URI Problem 2388 Solution Tachograph - URI Online Judge Solution

URI Online Judge Solution 2388 Tachograph Using Python Programming Language. Tachographs are devices installed on certain types of vehicles, which record the speed, time and distance traveled by that vehicle. It is mainly used in public transport and cargo transport vehicles, thus helping to prevent speed abuses by drivers. The company SBC (Sociedade Brasileira dos Caminhoneiros) decided to order a slightly more basic (and cheaper) version so that its members do not have to spend so much on installing these devices. These modified versions record only the time intervals and average truck speeds at those intervals. Despite the restrictions of the new devices, SBC wants to be able to know how far the trucks traveled. You must write a program that receives a series of time intervals with their respective average speeds and calculates the total distance traveled by the truck according to the tachograph. Input The first line of the entry contains an integer N (1 ≤ N ≤ 1000) representing the...

URI Problem 2374 Solution Pneu - URI Online Judge Solution

URI Online Judge Solution 2374 Pneu Using Python Programming Language.   Calibrar os pneus do carro deve ser uma tarefa cotidiana de todos os motoristas. Para isto, os postos de gasolina possuem uma bomba de ar. A maioria das bombas atuais são eletrônicas, permitindo que o motorista indique a pressão desejada num teclado. Ao ser ligada ao pneu, a bomba primeiro lê a pressão atual e calcula a diferença de pressão entre a desejada e a lida. Com esta diferença ela esvazia ou enche o pneu para chegar na pressão correta. Sua ajuda foi requisitada para desenvolver o programa da próxima bomba da SBC - Sistemas de Bombas Computadorizadas. Escreva um programa que, dada a pressão desejada digitada pelo motorista e a pressão do pneu lida pela bomba, indica a diferença entre a pressão desejada e a pressão lida. Input A primeira linha da entrada contém um inteiro N que indica a pressão desejada pelo motorista (1 ≤ N ≤ 40). A segunda linha contém um inteiro M que indica a pressão lida pela bomba...

URI Problem 2058 Solution Triangles and Regular Polygons - URI Online Judge Solution

URI Online Judge Solution  2058 Triangles and Regular Polygons  Using Python Programming Language.   Professor Rafael loves Computer Graphics. Its favourite activity is rendering objects, specially dolls. But he does not like to draw regular polygons using triangles. This task is done by composing a regular polygon using only triangles, in such a way that the triangles do not intercept each other and the minimum number of them are used in this composition. In the picture below you can see a square and a pentagon with its triangles. Professor Rafael asked you to calculate the minimum number of triangles necessary to compose a N-sided regular polygon. Input The input is a single number N (3 ≤ N ≤ 109), indicating the number of sides of a regular polygon. Output The output is the minimum number of triangles necessary to compose an N-sided regular polygon. Input Samples Output Samples 3 1 4 2 5 3 Solution Using Python: N = int(input()) print(N-2)

URI Online Judge Solution 1087 Queen

URI Online Judge Solution 1087 Queen using Python Programming Language. The game of Chess has several pieces with curious movements. One of them is the  Queen , which can move any number of squares in any direction: in the same line, in the same column or in any of the diagonals, as illustrated by the figure below (black dots represent positions the queen may reach in one move): The great Chess Master Kary Gasparov invented a new type of chess problem: given the position of a queen in an empty standard chess board (that is, an 8 x 8 board) how many moves are needed so that she reaches another given square in the board? Kary found the solution for some of those problems, but is having a difficult time to solve some others, and therefore he has asked that you write a program to solve this type of problem. Input The input contains several test cases. The only line of each test case contains four integers  X 1 ,  Y 1 ,  X 2  and  Y 2  (...

URI Online Judge Solution 1026 To Carry or not to Carry

URI Online Judge Solution 1026 To Carry or Not to Carry using Python Programming Language. 6+9=15 seems okay. But how come 4+6=2? Look at, Mofiz worked hard throughout his Digital Logic course, but when he was asked to implement a 32 bit adder for the laboratory exam, he did some mistake in the design part. After scavenging the design for half an hour, he found his flaw!! He was doing bitwise addition but his carry bit always had zero output. Thus, 4  = 00000000 00000000 00000000 00000100 +6 = 00000000 00000000 00000000 00000110 ---------------------------------------- 2  = 00000000 00000000 00000000 00000010 It’s a good thing that he finally found his mistake, but it was too late. Considering his effort throughout the course, the instructor gave him one more chance. Mofiz had to write an efficient program that would take 2 unsigned 32 bit decimal numbers as input, and produce an unsigned 32 bit decimal number as the output adding in the same way as his circ...