Cod sursa(job #466150)

Utilizator ChallengeMurtaza Alexandru Challenge Data 26 iunie 2010 11:27:36
Problema Fibo3 Scor 100
Compilator cpp Status done
Runda Stelele Informaticii 2010, gimnaziu si clasa a IX-a, Ziua 2 Marime 1.77 kb
#include <fstream>

using namespace std;

const char InFile[]="fibo3.in";
const char OutFile[]="fibo3.out";

ifstream fin(InFile);
ofstream fout(OutFile);

unsigned long long v[]={1LL, 2LL, 3LL, 5LL, 8LL, 13LL, 21LL, 34LL, 55LL, 89LL, 144LL, 233LL, 377LL, 610LL, 987LL, 1597LL, 2584LL, 4181LL, 6765LL, 10946LL, 17711LL, 28657LL, 46368LL, 75025LL, 121393LL, 196418LL, 317811LL, 514229LL, 832040LL, 1346269LL, 2178309LL, 3524578LL, 5702887LL, 9227465LL, 14930352LL, 24157817LL, 39088169LL, 63245986LL, 102334155LL, 165580141LL, 267914296LL, 433494437LL, 701408733LL, 1134903170LL, 1836311903LL, 2971215073LL, 4807526976LL, 7778742049LL, 12586269025LL, 20365011074LL, 32951280099LL, 53316291173LL, 86267571272LL, 139583862445LL, 225851433717LL, 365435296162LL, 591286729879LL, 956722026041LL, 1548008755920LL, 2504730781961LL, 4052739537881LL, 6557470319842LL, 10610209857723LL, 17167680177565LL, 27777890035288LL, 44945570212853LL, 72723460248141LL, 117669030460994LL, 190392490709135LL, 308061521170129LL, 498454011879264LL, 806515533049393LL, 1304969544928657LL};
unsigned long long x1,x2,y1,y2;
int N;

inline unsigned long long minA(unsigned long long a, unsigned long long b)
{
    if(a>b)return b;
    return a;
}

int main()
{
    fin>>N;
    for(register int i=0;i<N;++i)
    {
        fin>>x1>>y2>>x2>>y1;
        unsigned long long R=0;
        for(register int i=0;i<73;++i)
        {
            unsigned long long t=v[i];
            if(t-x1>=y2 && t-x1<=y1 && t>=x1)
            {
                R+=minA(x2-x1+1,(t-x1)-y2+1);
            }
            else if(t-y1>=x1 && t-y1<=x2 && t>=y1)
            {
                R+=minA(y1-y2+1,x2-(t-y1)+1);
            }
        }
        fout<<R<<"\n";
    }
    fout.close();
    fin.close();
    return 0;
}