#8838: TLE....


s10230308 (郎若回頭不是報恩就是爆扣)

學校 : 臺北市立成功高級中學
編號 : 34402
來源 : [118.169.5.193]
最後登入時間 :
2021-08-13 08:09:14
d188. 11342 - Three-square -- UVa11342 | From: [203.64.138.43] | 發表日期 : 2014-05-28 10:43

請教大大幫忙 

#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
int main()
{
    int x,i,t,k,a,flag;
    scanf("%d",&x);
    while(x--)
    {
        flag=0;     
        scanf("%d",&a);
        for(i=0;i<sqrt(a);i++)
        {
          if(flag==1) break;
          for(t=i;t<sqrt(a);t++)
          {
             if(flag==1) break;                   
             for(k=t;k<=sqrt(a);k++)
                if(i*i+t*t+k*k==a){              
                   flag=1;break;}
          }
        } 
        if(flag==1)
           cout<<i-1<<" "<<t-1<<" "<<k<<"\n";
        else
           cout<<"-1\n";
    }     
  return 0;
}

 
#16588: Re:TLE....


hshua (hshua)

學校 : 新北市立林口高級中學
編號 : 52506
來源 : [163.20.185.250]
最後登入時間 :
2024-03-15 09:17:14
d188. 11342 - Three-square -- UVa11342 | From: [220.133.124.236] | 發表日期 : 2019-01-19 17:12

請教大大幫忙 

#include
#include
#include
using namespace std;
int main()
{
    int x,i,t,k,a,flag;
    scanf("%d",&x);
    while(x--)
    {
        flag=0;     
        scanf("%d",&a);
        for(i=0;i<sqrt(a);i++)
        {
          if(flag==1) break;
          for(t=i;t<sqrt(a);t++)
          {
             if(flag==1) break;                   
             for(k=t;k<=sqrt(a);k++)
                if(i*i+t*t+k*k==a){              
                   flag=1;break;}
          }
        } 
        if(flag==1)
           cout<<i-1<<" "<<t-1<<" "<<k<<"\n";
        else
           cout<<"-1\n";
    }     
  return 0;
}


要先建查詢表才能通過 TLE,大約 (0~225)*(0~225)*(0~225),
結果對應字串,例如: 1:'0 0 1', 2:'0 1 1', 5:'0 1 2' ...

 
ZeroJudge Forum