Re: 11407 - Squares
Posted: Fri Jun 27, 2008 8:17 am
Thnx Jan.Your help helped me.
Finally I got ACC.
Keep posting.
Bye.
Finally I got ACC.
Keep posting.
Bye.
Code: Select all
#include<iostream>
#include<cmath>
#include<fstream>
using namespace std;
int go (double n,int j)
{
int max=0;
if(n==0) return max;
n-=double(j*j);
j=int(sqrt(n));
max++;
max+= go(n,j);
return max;
}
int main()
{
//ifstream cin("a.txt");
int t,max=0,best=1000;
double n;
cin>>t;
for(int i=0;i<t;i++)
{
cin>>n;
best=1000;
for(int j=int(sqrt(n));j>0;j--)
{
max=go(n,j);
if(max<best)
best=max;
}
cout<<best<<endl;
}
return 0;
}
Well, I think go() function should do the same thing as the main() does.. (looping j from sqrt(n) to 1)masteringminds wrote:mmmm...mine outputs 4
ok what do u think is the error?
Code: Select all
14
9999
10000
1
1001
4546
3467
2368
8990
2321
6789
3421
1256
1244
5467
Code: Select all
4
1
1
3
2
3
2
3
3
3
3
2
4
3
Code: Select all
#include <math.h>
#include <stdio.h>
int main(){
int n,k=0,occ,max,t,i,j,a;
scanf("%d",&n);
while(k<n){
scanf("%d",&a);
max=100;
if(a==0) max=1;
for(j=int(sqrt(a));j>=1;j--){
i=j;
t=a;
occ=0;
while((i>=1)&(t>0)){
if(i*i<=t){
t-=i*i;
occ++;}
else
i--;
}
if(occ<max) max=occ;
}
printf("%d\n",max);
k++;
}
return 0;
}