Showing posts with label Volume 118 (11800-11899). Show all posts
Showing posts with label Volume 118 (11800-11899). Show all posts

Saturday, December 21, 2013

11854 - Egypt


Problem A: Egypt

A long time ago, the Egyptians figured out that a triangle with sides of length 3, 4, and 5 had a right angle as its largest angle. You must determine if other triangles have a similar property.

The Input

Input represents several test cases, followed by a line containing 0 0 0. Each test case has three positive integers, less than 30,000, denoting the lengths of the sides of a triangle.

The Output

For each test case, a line containing "right" if the triangle is a right triangle, and a line containing "wrong" if the triangle is not a right triangle.

Sample Input

6 8 10
25 52 60
5 12 13
0 0 0

Output for Sample Input

right
wrong
right
 
Solution: 
#include <stdio.h>

int main(){
 static int A, B, C, D; 
 while(scanf("%d %d %d", &A, &B, &C) == 3 && (A || B || C)){  
  if(A >= B){
   if(A > C){
    D = A;
    A = C;
    C = D;
   }
  }else if(B > C){
   D = B;
   B = C;
   C = D;
  } 
   
  if(A*A+B*B == C*C)
   printf("right\n");
  else
   printf("wrong\n");   
 }
 return 0;
}

11805 - Bafana Bafana


B
Bafana Bafana

Team practice is very important not only for programming contest but also for football. By team practice players can learn cooperating with team mates.  For playing as a team improvement of passing skill is very important. Passing is a great way of getting the ball upfield and reduces the risk of giving the ball away.

Carlos Alberto Parreira, the coach of Bafana Bafana, also wants his players to practice passing a lot. That’s why, while in the training camp for soccer world cup 2010, every day he asks all of the players who are present in practice to stand in a circle and practice passing. If N players are in practice, he gives each of the players a distinct number from 1 to N, and asks them to stand sequentially, so that player 2 will stand in right side of player 1 and player 3 will stand in right side of player 2, and so on. As they are in a circle, player 1 will stand right to player N.

The rule of passing practice is, Parreira will give the ball to player K, and practice will start. Practice will come to an end after P passes. In each pass, a player will give the ball to his partner who is in his immediate right side. After P passes, the player who owns the ball at that moment will give the ball back to Parreira.

Parreira wants to be ensured that his players practice according the rule. So he wants a program which will tell him which player will give him the ball back. So after taking the ball from the same person he can be happy that, the players play according to the rules. Otherwise he will ask them to start from beginning.


Input
Input starts with an integer T (T <= 1000), the number of test cases. Each test case will contain three integers, N (2 <= N <= 23), K (1 <= K <= N), P(1<=P<=200).

Output
For each test case, output a single line giving the case number followed by the Bafana player number who will give the ball to Parreira. See sample output for exact format.
Sample Input
Sample Output
3
5 2 5
6 3 5
4 1 3
Case 1: 2
Case 2: 2
Case 3: 4

Problemsetter: Md. Arifuzzaman Arif, Special Thanks: Muntasir Khan, Sohel Hafiz

Solution
#include <stdio.h>

int main(){
    static int T, t, N, K, P;
    scanf("%d", &T);
    for(t = 1; t <= T; t++){
        scanf("%d%d%d", &N, &K, &P);
        K = (K+P)%N;
        if(!K)
            K = N;
        printf("Case %d: %d\n", t, K);   
    }
    return 0;
}