Pagini: 1 [2]   În jos
  Imprimă  
Ajutor Subiect: 316 Chiftea  (Citit de 13105 ori)
0 Utilizatori şi 1 Vizitator pe acest subiect.
PetrutiuPaul
Strain


Karma: 0
Deconectat Deconectat

Mesaje: 1



Vezi Profilul
« Răspunde #25 : Martie 31, 2013, 18:22:01 »

imi puteti da niste teste mai complicate ?
ori ce dau eu imi da bn:|
Memorat
AndreiIT
Strain


Karma: 0
Deconectat Deconectat

Mesaje: 3



Vezi Profilul
« Răspunde #26 : Noiembrie 15, 2014, 09:36:10 »

de ce am luat doar 50 de puncte la sursa asta(http://www.infoarena.ro/job_detail/1263790?action=view-source)

#include <fstream>
#include <cmath>
using namespace std;
ifstream fin ("chiftea.in");
ofstream fout ("chiftea.out");
int main()
{
    int t,n,sol;
    fin>>t;
    for(int i=t;i>=1;i--)
    {
        fin>>n;
        if(n==1)
            fout<<"4"<<'\n';
        if(n==2)
            fout<<"6"<<'\n';
        if(n==3)
            fout<<"8"<<'\n';
        if(n>=4)
        {
            int x=sqrt(n);
                sol=x*4;
            if(x*x+x>=n and x*x!=n)
                sol+=2;
            if(x*x+x<n)
                sol+=4;
        }
        fout<<sol<<'\n';
    }

    return 0;
}
Memorat
PlayLikeNeverB4
Nu mai tace
*****

Karma: 212
Deconectat Deconectat

Mesaje: 721



Vezi Profilul
« Răspunde #27 : Noiembrie 15, 2014, 12:48:21 »

sqrt poate avea erori de precizie. Daca calculezi sqrt(4) poate sa iti rezulte 1.999999 care devine 1 cand ii faci cast la int.
Memorat
DeehoroEjkoli
Strain


Karma: 0
Deconectat Deconectat

Mesaje: 4



Vezi Profilul
« Răspunde #28 : Februarie 25, 2015, 19:54:22 »

 Am studiat vreo 20-30 de cazuri si pentru toate codul de mai jos era bun, eu am gasit trei cazuri (cand e patrat perfect, cand nu e patrat perfect si e impar, cand e patrat perfect si e par):

#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;
ifstream f("chiftea.in");
ofstream g("chiftea.out");
int t,x,i;
int main()
{
    f>>t;
    for (i=1;i<=t;i++)
    {f>>x;
    if (sqrt(x)==(int)(sqrt(x)))
        g<<x-(pow(sqrt(x)-2,2))+4<<"\n";

    if (sqrt(x)!=(int)(sqrt(x))&&x%2==0)
        g<<x+4<<"\n";

    if (sqrt(x)!=(int)(sqrt(x))&&x%2==1)
        g<<x+5<<"\n";
    }
    return 0;
}
  Brick wall
Memorat
Cez2804
Strain


Karma: 0
Deconectat Deconectat

Mesaje: 2



Vezi Profilul
« Răspunde #29 : Februarie 21, 2016, 22:50:16 »

 Read This!
Memorat
Pagini: 1 [2]   În sus
  Imprimă  
 
Schimbă forumul:  

Powered by SMF 1.1.19 | SMF © 2006-2013, Simple Machines