Cod sursă (job #230879)

Utilizator avatar andreiflorescu99 Andrei Florescu andreiflorescu99 IP ascuns
Problemă Romb2 (clasele 9-10) Compilator cpp | 2,60 kb
Rundă Arhiva de probleme Status evaluat
Dată 4 apr. 2016 14:19:53 Scor 0
#include <iostream>
#include <fstream>

using namespace std;

bool panta (float x, float y, float dx, float dy) {
    //cout << y / x << " " << dy / dx << "\n";
    if ((y / x) > (dy / dx)) {
        return 1;
    }
    return 0;
}

int solutie (int ord, float x, float y, float dx, float dy, int zona) {

    if (ord == 0) {
        return zona;
    }
    if (x > 0) {
        if (y > 0) {        // NE
            if (panta (x, y, dx / 2, dy / 2) == 1) {                                                 // zona I
                return solutie (ord - 1, x, y - (dy / 2), dx / 2, dy / 2, (4 * zona) - 3);
            } else {                                                                                // zona IV
                return solutie (ord - 1, x - (dx / 2), y, dx / 2, dy / 2, (4 * zona));
            }
        } else {            // SE
            if (panta (x, y, dx / 2, -dy / 2) == 1) {                                                 // zona IV
                return solutie (ord - 1, x - (dx / 2), y, dx / 2, dy / 2, (4 * zona));
            } else {                                                                                // zona III
                return solutie (ord - 1, x, y + (dy / 2), dx / 2, dy / 2, (4 * zona) - 1);
            }
        }
    } else {
        if (y > 0) {        // NV
            if (panta (x, y, -dx / 2, dy / 2) == 0) {                                                 // zona I
                return solutie (ord - 1, x, y - (dy / 2), dx / 2, dy / 2, (4 * zona) - 3);
            } else {                                                                                // zona II
                return solutie (ord - 1, x + (dx / 2), y, dx / 2, dy / 2, (4 * zona) - 2);
            }
        } else {            // SV
            if (panta (x, y, -dx / 2, -dy / 2) == 0) {                                                 // zona II
                return solutie (ord - 1, x + (dx / 2), y, dx / 2, dy / 2, (4 * zona) - 2);
            } else {                                                                                // zona III
                return solutie (ord - 1, x, y + (dy / 2), dx / 2, dy / 2, (4 * zona) - 1);
            }
        }
    }
}

int main() {
    ifstream file_in ("romb.in");
    ofstream file_out ("romb.out");

    int t;
    int dx, dy, ord, x, y;

    // Citirea datelor
    file_in >> t;

    // Calcularea solutiei
    for (; t > 0; t--) {
        file_in >> dx >> dy >> ord >> x >> y;
        // Afisarea solutiei
        file_out << solutie (ord, x, y, dx, dy, 1) << "\n";
    }

    return 0;
}