/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 2ms 532.0 KiB
#4 Accepted 1ms 532.0 KiB
#5 Accepted 2ms 324.0 KiB
#6 Accepted 1ms 324.0 KiB
#7 Accepted 1ms 764.0 KiB
#8 Accepted 1ms 532.0 KiB
#9 Accepted 7ms 532.0 KiB
#10 Accepted 5ms 532.0 KiB
#11 Accepted 1ms 532.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
// special case 1009
// Cmax =  floor((B^2)/2)+1;

void solve2()
{
    ll B,h,H,sqH,ans,hh,BB; cin>>B;
    BB = B*B;
    for(ll h=1;h<=10000000;h++)
    {
        hh = h*h;
        H = BB+hh;
        sqH = sqrt(H);
        if(sqH*sqH==H)
        {
            cout<<"base = "<<B<<endl;
            cout<<"hight= "<<h<<endl;
            cout<<"hypo = "<<sqH<<endl;
            cout<<endl;
        }
    }
}

//ofstream file("output0.txt");
void solve()
{
    ll B,h,H,sqH,ans,hh,sqB; cin>>B;
    sqB = B*B;
    ll limit = (sqB/2)+5;
    ans=-1;
    for(ll h=limit;h>=1;h--)
    //for(ll h=1000000;h>=1;h--) //timeout
    {
        sqH = sqB+h*h;
        H = sqrt(sqH);
        if(H*H==sqH)
        {
            ans=H+B+h;
            break;
        }
    }
    cout<<ans<<endl;
    //file<<ans<<endl;
}
int main()
{
    
    int t; cin>>t; while(t--) solve();
   // file.close();
}

Information

Submit By
Type
Submission
Problem
P1027 Right triangle
Language
C++20 (G++ 13.2.0)
Submit At
2024-01-15 10:31:45
Judged At
2024-11-11 03:43:29
Judged By
Score
100
Total Time
7ms
Peak Memory
764.0 KiB