Here is my code.
Code: Select all
removed
Moderator: Board moderators
Code: Select all
removed
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.
Code: Select all
removed
We have three different integers, x, y and z,
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;
}
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
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.