TJU Problem 3013 Solution

Greetings,

First problem I solve on TJU… figured I’d start posting these up here…

Alfredo’s Pizza Restaurant¬†isn’t such a complex question, very straight forward math… There aren’t any secrets to the code really, fairly simple question to solve.

 

C++ Solution: This solution is linear, brute force solution.

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>

using namespace std;

int main()
{
   int r, w, l, count=1;
   double pizzaRadius=0.0;

   while(true)
   {
      scanf("%d",&r);
      if(r==0) break;
      scanf("%d%d",&w,&l);
      pizzaRadius = sqrt( (w*1.0)*(w*1.0) + (l*1.0)*(l*1.0) ) / 2.0;
      if( pizzaRadius <= r*1.0 )
         printf("Pizza %d fits on the table.n",count);
      else
         printf("Pizza %d does not fit on the table.n",count);
      count++;
   }

   return 0;
}
									

**For some odd reason the code box is eliminating small things like back slashes (\). So the little typos aren’t really my fault… this question has been submitted and accepted by the TJU website. **

 

Java Solution: It has a small bug… not in the Algorithm, but somewhere small… I wanna show an algorithm, not give code for free solutions :P

import java.util.Scanner;
import java.lang.Math;

public class TJU3013 {

  public static void main (String[] args){
    Scanner input = new Scanner(System.in);
    int count = 1;
    int r, l, w;
    double PizzaRadius = 0.0;
    while(true){
      r = input.nextInt();
      if(r == 0)
        break;
      l = input.nextInt();
      w = input.nextInt();
      PizzaRadius = Math.sqrt((w*1.0)*(w*1.0) + (l*1.0)*(l*1.0)) / 2.0;
      if(PizzaRadius <= r*1.0)
        System.out.printf("Pizza %d fits on table.n", count);
      else
        System.out.printf("Pizza %d does not fit on the table.n", count);
      count++;
    }
      
  }
}
									

Leave a Reply

Your email address will not be published. Required fields are marked *