-
Notifications
You must be signed in to change notification settings - Fork 3
/
427-FlatLandPianoMovers.cpp
executable file
·83 lines (71 loc) · 1.65 KB
/
427-FlatLandPianoMovers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//
// 427 - FlatLand Piano Movers.cpp
// Uva
//
// Created by Alexander Faxå on 2012-02-26.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#define EPS 1e-10
#define pi acos(-1)
using namespace std;
//piano width, piano length, corridor a, corridor b
int nbrs[4];
int cur, cur_index;
void solve()
{
if(cur != 0) // some number is read
{
nbrs[cur_index++] = cur;
cur = 0;
if(cur_index == 4) // a new corridor config is ready
{
cur_index = 2;
if(nbrs[0] > nbrs[1]) // piano width > piano length
swap(nbrs[0], nbrs[1]);
for (double a = 0.00001; a < pi/2; a += pi/256)
{
double cur_max_length = (nbrs[2] * sin(a) + nbrs[3] * cos(a) - nbrs[0]) / (sin(a) * cos(a));
if(cur_max_length < (double)nbrs[1]+ EPS)
{
cout << "N";
return;
}
}
cout << "Y";
return;
}
}
}
int main()
{
string line;
while(getline(cin, line))
{
cur_index = 0;
cur = 0;
for(int i=0;;i++)
{
if(line[i] == '\n' || line[i] == '\0')
{
solve();
break;
}
else if(line[i] == ' ' || line[i] == ',')
{
solve();
continue;
}
else
{
cur = cur * 10 + (line[i] - '0');
}
}
cout << endl;
}
return 0;
}