
Input
The input contains a single floating-point number x with exactly 6 decimal places (0 < x < 5).
Output
Output two integers separated by a single space. Each integer should be between 1 and 10, inclusive. If several solutions exist, output any of them. Solution will exist for all tests.
Examples
input
1.200000
output
3 2
input
2.572479
output
10 3
input
4.024922
output
9 9
Solution:
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>
using namespace std;
int main() {
double x;
scanf("%lf", &x);
double diff = 12345;
int da = -1, db = -1;
for (int a = 1; a <= 10; a++)
for (int b = 1; b <= 10; b++) {
double u = (a * b) / sqrt(4 * a * a + b * b);
u = fabs(u - x);
if (u < diff) {
diff = u;
da = b;
db = a;
}
}
printf("%d %d\n", da, db);
return 0;
}
Related posts:
Gauss method for solving system of linear equations
Metro
Number Transformation
Balanced Ternary
Bear and Destroying Subtrees
Long Beautiful Integer
Edge connectivity / Vertex connectivity
Number of paths of fixed length / Shortest paths of fixed length
Travelling Through the Snow Queen's Kingdom
Potions Homework
Restoring Three Numbers
PolandBall and Hypothesis
Square Table
New Year and Domino
A Game on Strings
Dexterina’s Lab
T-shirt buying
Make It One
Memory for Arrays
Banana
Businessmen Problems
Circle-Line Intersection
Paint it really, really dark gray
Weather Tomorrow
More Reclamation
New Year Permutation
The Chocolate Spree
Reposts
Ehab the Xorcist
New Year and the Permutation Concatenation
Declined Finalists
Kay and Snowflake