Fibsieve`s Fantabulous Birthday LightOJ - 1008 (water, but a little pit)

Fibsieve`s Fantabulous Birthday (water, but a little pit)

Topic Link
Here Insert Picture Description

Begin to see the data to know what hit the table are absolutely to die, but did not go to look carefully the time limit, it is intended:
If s not a square, then find its corresponding larger than its smallest perfect square
if it is completely that simple square of: determining directly determined by parity which is x = = 1 or y = = 1

Because it may be turning , for example: s == 19, if only to find 25 then x-, this is definitely not going to work, that is, to turn

I began to think that with a small circulation (he died on the topic did not look carefully when) the time limit is 0.5s , this will certainly TLE

Also stepped on a small dip, this is a low-level errors, in front of the Case did not add, I am also the Buddha himself

A final modification finally, this water problem out of mind a little collapse. . . . . . . . . . .

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#define ll long long
using namespace std;
int main(){
    int t;
    ll s;
    ll x,y;
    scanf("%d",&t);
    for(int k=1;k<=t;k++){
        scanf("%lld",&s);
        ll num=sqrt(s);
        //cout<<num<<endl;
        if(num*num==s){
            if(num%2==1){
                printf("Case %d: 1 %lld\n",k,num);
            }
            else
            {
                printf("Case %d: %lld 1\n",k,num);
            }
            continue;
        }
        //cout<<num<<endl;
        ll cnt=num+1;
        if(cnt%2==1){
            x=1;
            y=cnt;
            ll n=cnt*cnt-s;
            if(n<cnt){
                x=n+1;
            }
            else{
                x=cnt;
                y=cnt-(n-cnt)-1;
            }
        }
        else{
            y=1;
            x=cnt;
            ll n=cnt*cnt-s;
            if(n<cnt){
                y=n+1;
            }
            else{
                y=cnt;
                x=cnt-(n-cnt)-1;
            }
        }
        printf("Case %d: %lld %lld\n",k,x,y);
    }
    return 0;
}

Here Insert Picture Description

0 seconds to see this very comfortable

Published 127 original articles · won praise 32 · views 10000 +

Guess you like

Origin blog.csdn.net/boliu147258/article/details/102296471