### 11565 - Simple Equations

Posted:

**Sun Dec 28, 2008 9:11 am**Some one please help me I got so many WA in the contest and getting WA till now.

Here is my code.

Here is my code.

Code: Select all

`removed`

The Online Judge board

https://uva.onlinejudge.org/board/

https://uva.onlinejudge.org/board/viewtopic.php?f=50&t=42554

Page **1** of **2**

Posted: **Sun Dec 28, 2008 9:11 am**

Some one please help me I got so many WA in the contest and getting WA till now.

Here is my code.

Here is my code.

Code: Select all

`removed`

Posted: **Sun Dec 28, 2008 9:45 am**

Read the statement more carefully ....

And you will find your bug!!!

And you will find your bug!!!

Posted: **Sun Dec 28, 2008 9:57 am**

Are you aiming for that???

But i can't find any difference between it and my solution.If there are many possible answers, choose the one with the least value of x. If there is a tie, output the one with the least value of y.

Posted: **Sun Dec 28, 2008 10:20 am**

No, try this test:

3 1 3

Right answer is: No solution!

3 1 3

Right answer is: No solution!

Posted: **Sun Dec 28, 2008 10:46 am**

But now check this. It's also WA.

Code: Select all

`removed`

Posted: **Sun Dec 28, 2008 11:01 am**

I think this test will help you:

1 120 245

Answer is: -10 -1 12

1 120 245

Answer is: -10 -1 12

Posted: **Sun Dec 28, 2008 11:04 am**

Thank you very much i got the idea now.

Posted: **Sun Dec 28, 2008 7:02 pm**

thanx..Articuno

Posted: **Sun Dec 28, 2008 8:44 pm**

The reason is described in the first line of the problem descryption.

We have three different integers, x, y and z,

Posted: **Tue Dec 30, 2008 9:18 pm**

sorry about my wrong input.

Posted: **Tue Dec 30, 2008 9:28 pm**

input is not right!

Posted: **Wed Dec 31, 2008 12:23 am**

edited

Posted: **Wed Dec 31, 2008 11:48 am**

I dont understand what you want to say, If you are asking about inputs>10000 and <1 then this should not be a concern. The problem descryption defines that all inputs will be within that range.

Posted: **Sat Jan 03, 2009 5:49 am**

Artincuno is right. The input numbers are all in the specified range. In fact the largest number in the input file is a bit less than 10000.

Posted: **Tue Jan 13, 2009 9:30 pm**

I am sorry for my previous wrong input.

anyway I got AC in O(n^2) solution.

but I am getting WA in O(n) solution...pliz anyone help.

code:
Is there any wrong finding the value of x , y? Is my equation right?

sample input:

sample output:

anyway I got AC in O(n^2) solution.

but I am getting WA in O(n) solution...pliz anyone help.

code:

Code: Select all

```
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int valy,valz,valx,x,y,z,a,b,c,u,v,m,n,t;
bool flag;
#define inf 32767
int cal(){
int beg,end;
beg=-b;
while(beg<=b){
int i=beg;
v=2*i*i*i-2*a*i*i+a*a*i-c*i-2*b;
if(!v&&i)return i;
beg++;
}
return inf;
}
void fun(){
m=-m;
valy=(m+a-valx)/2;
if(valy==inf||valy==0||valy==valx)return;
valz=b/(valx*valy);
if(valz==inf||valz==0||valz==valx||valz==valy)return;
if(valx*valx+valy*valy+valz*valz!=c||valx*valy*valz!=b||valx+valy+valz!=a)return;
int y=max(valx,valy);
int x=valx+valy-y;
int z=a-x-y;
if(z>y)valx=x,valy=y,valz=z;
else if(z>x)valx=x,valy=z,valz=y;
else valx=z,valy=x,valz=y;
flag=true;
}
int main(){
int i,j,k,l;
#ifndef OINLINE_JUDGE
freopen("1.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
scanf("%d",&t);
while(t--){
scanf("%d%d%d",&a,&b,&c);
valx=cal();
if(valx==inf){printf("No solution.\n");continue;}
m=c-valx*valx-2*(b/valx);
m=sqrt(double(m))+.5;
flag=false;
fun();
if(!flag)fun();
if(flag)printf("%d %d %d\n",valx,valy,valz);
else printf("No solution.\n");
}
return 0;
}
```

sample input:

Code: Select all

```
29
3 1 3
3 3 3
1 8 21
17 108 121
10 0 100
47 240 1637
18 0 162
23 385 195
37 1664 489
17 0 145
44 544 1224
42 0 1394
24 0 386
12 24 74
8 0 40
55 629 1659
60 1410 2318
34 836 498
46 980 1290
19 56 213
11 48 41
57 3468 1481
52 2210 1350
8 0 130
0 30 38
0 30 38
1 4 9
5 0 13
3 0 5
```

sample output:

Code: Select all

```
No solution.
No solution.
-2 -1 4
2 6 9
No solution.
1 6 40
No solution.
5 7 11
8 13 16
No solution.
2 8 34
No solution.
No solution.
1 3 8
No solution.
1 17 37
3 10 47
4 11 19
4 7 35
1 4 14
No solution.
6 17 34
5 13 34
No solution.
-3 -2 5
-3 -2 5
No solution.
No solution.
No solution.
```