UVA Solution 427 - FlatLand Piano Movers - Volume 4 - Online Judge Solution

Latest

It is a free Online judges problems solution list. Here you can find UVA online Judge Solution, URI Online Judge Solution, Code Marshal Online Judge Solution, Spoz Online Judge Problems Solution

Thursday, May 11, 2017

UVA Solution 427 - FlatLand Piano Movers - Volume 4

UVA Solution 427 - FlatLand Piano Movers - Volume 4


UVA Online Judge Solution 427 - FlatLand Piano Movers | Volume 4
UVA Problem Link - https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=6&page=show_problem&problem=368

Problem Name: 427 - FlatLand Piano Movers
Problem Number : UVA - 427 - FlatLand Piano Movers
Online Judge : UVA Online Judge Solution
Volume: 4
Solution Language : C plus plus

UVA Solution 427 - FlatLand Piano Movers - Volume 4

UVA Solution 427 - FlatLand Piano Movers Code in CPP:


#include <stdio.h> 
#include <math.h>
#include <string.h>
#include <iostream>
#include <sstream>
#include <algorithm>
using namespace std;
const double pi = acos(-1);
#define eps 1e-6 
double ternary_search(double H, double W, double X, double Y) {
 double l = 0, r = pi /2, mid, midmid;
 double s1, h1, s2, h2;
 while(fabs(l - r) > eps) {
  mid = (l + r) /2;
  midmid = (mid + r) /2;
  s1 = H * cos(mid) + W * sin(mid) - X;
  h1 = s1 * tan(mid) + W * cos(mid);
  s2 = H * cos(midmid) + W * sin(midmid) - X;
  h2 = s2 * tan(midmid) + W * cos(midmid);
  if(h1 < h2)
   l = mid;
  else
   r = mid;
 }
 return h1;
}
int main() {
 char line[1024];
 while(gets(line)) {
  stringstream sin(line);
  string token;
  sin >> token;
  double H, W, X, Y;
  sscanf(token.c_str(), "%lf,%lf", &H, &W);
  if(H < W)
   swap(H, W);
  while(sin >> token) {
   sscanf(token.c_str(), "%lf,%lf", &X, &Y);
   double h = ternary_search(H, W, X, Y);
   printf("%c", h <= Y ? 'Y' : 'N');
  }
  puts("");
 }
 return 0;
}

Tags: UVA Online Judge Solution, UVA OJ Solution list, UVA Problems Solution, UVA FlatLand Piano Movers Solution, FlatLand Piano Movers code in C, UVA FlatLand Piano Movers code in C++

No comments:

Post a Comment