1 /*
2 Problem link
3 Type: Complete Search
4 Algorithm:
5 Obviously, from equation 2, if x = y = z = 100,
6 then 100^3 = 10^6 > 10^5. Therefore, all three
7 numbers must be less than 100, this is enough for
8 the problem to get AC :).
9 */
10 #include <iostream>
11 #include <cstdio>
12 #include <cstring>
13 #include <cmath>
14 #include <cstdlib>
15
16 using namespace std;
17 bool solve(int a, int b, int c);
18
19 int main()
20 {
21 int nTest,
22 a,b,c;
23 cin >> nTest;
24 while (nTest--) {
25 cin >> a >> b >> c;
26 if (!solve(a,b,c)) cout << "No solution." << endl;
27 }
28 return 0;
29 }
30
31 bool solve(int a, int b, int c) {
32 for (int i = -100; i <= 100; i++)
33 for (int j = -100; j <= 100; j++)
34 for (int k = -100; k <= 100; k++)
35 if (i!=j && j!=k && i!=k &&
36 i+j+k == a && i*j*k == b && i*i+j*j+k*k == c) {
37 cout << i << " " << j << " " << k << endl;
38 return true;
39 }
40 return false;
41 }
Introduction
This is my blog of programming, I take notes and leave codes of computer science problems I solved here. Be my guest to comment :)
Saturday, June 22, 2013
UVa 11565 - Simple Equations
Labels:
Complete search
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment