ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1073. Square Country

Help Why WA
Posted by yuxiaolei 17 Dec 2006 07:18
//1073
#include<iostream>
#include<cmath>
using namespace std;
unsigned long mn;
bool fine;
unsigned long sch(unsigned long n,unsigned long stpos,unsigned long time)
{
    if ((fine==true)&&(time==mn-1)){
        return(1);
    }else{
        n=n-stpos*stpos;
        if (n==0) {
            fine=true;
            return(1);
        }else{
            if (n<(stpos*stpos)) {
                stpos=int(floor(sqrt((long double)n)));
            }
            unsigned long submn,i,tmp;
            submn=sch(n,stpos,time+1);
            for (i=stpos-1;i>0;i--) {
                tmp=sch(n,i,time+1);
                if (tmp<submn) {
                    submn=tmp;
                }
            }
            return(submn+1);
        }
    }
}
int main (void)
{
    unsigned long n,rtfn;
    cin>>n;
    if (n==0) {
        cout<<0;
        return 0;
    }else{
    fine=0;
    rtfn=int(floor(sqrt((long double)n)));
    cout<<sch(n,rtfn,0);
    }
}
Re: Help Why WA
Posted by Ciprian 1 Dec 2007 15:42
I think some tests for you will be good;
for N=50000 answer is 2(explanation 1 piece 200*200 and the other 100*100)
N=0 0;
N=1 1