Cod sursă (job #513210)

Utilizator avatar am.001 Mihai Agrici am.001 IP ascuns
Problemă Romb2 (clasele 9-10) Compilator cpp | 2,00 kb
Rundă Arhiva de probleme Status evaluat
Dată 16 dec. 2019 12:51:55 Scor 50
#include <fstream>
#include <cmath>
#include <iostream>
#include <cstdlib>
using namespace std;
ifstream f("romb2.in");
ofstream g("romb2.out");
typedef long double ld;

struct punct
{
	ld x, y;
	inline void init_punct(ld xx, ld yy)
	{
		this->x = xx; this->y = yy;
	}
	inline void media(punct a, punct b)
	{
		this->x = (a.x + b.x) / 2.0;
		this->y = (a.y + b.y) / 2.0;
	}
};
int k, v1, v2, v3, v4, v5, v6, zona, T;
long long cod;
ld eps = 1.0e-7, ok;
punct d, p, p1, p2;
punct C, D, ab, bc, cd, da, O;

inline int verif(punct a, punct b, punct h)
{
    ok = a.x * b.y + b.x * h.y + h.x * a.y - b.y * h.x - h.y * a.x - a.y * b.x;
	if (abs( ok ) < eps)
	{
		cout << "testul nu e bun ", exit(0);
		g << "testul nu e bun ", g.close(), exit(0);
	}
	return (ok > 0 ? 1 : -1 );
}
inline void divide(punct A, punct B, int niv_k)












{
	if (niv_k > k) return ;
	zona = 0;
	C.init_punct( A.x , B.y + (B.y - A.y) ), D.init_punct( A.x + (A.x - B.x) , B.y );
	ab.media(A, B), bc.media(B, C), cd.media(C, D), da.media(D, A), O.media(A, C);
	v1 = verif(da, bc, p), v2 = verif(A, B, p), v3 = verif(D, C, p);
    v4 = verif(cd, ab, p), v5 = verif(D, A, p), v6 = verif(C, B, p);
	if (v1 * v2 < 0 && v4 * v5 < 0) zona = 1;
	else
	 if (v1 * v3 < 0 && v4 * v5 < 0) zona = 2;
	 else
	  if (v1 * v3 < 0 && v4 * v6 < 0) zona = 3;
	  else
	   if (v1 * v2 < 0 && v4 * v6 < 0) zona = 4;
    switch (zona)
    {
        case 1LL: cod = cod * 4LL - 3LL, divide(A, ab, niv_k + 1); break;
        case 2LL: cod = cod * 4LL - 2LL, divide(da, O, niv_k + 1); break;
        case 3LL: cod = cod * 4LL - 1LL, divide(O, bc, niv_k + 1); break;
        case 4LL: cod = cod * 4LL,       divide(ab, B, niv_k + 1);
    }
}

int main()















{
    f >> T;
	while (T)
	{
		f >> d.x >> d.y >> k;
		f >> p.x >> p.y;
		cod = 1;
		p1.init_punct(0.0, d.y), p2.init_punct(d.x, 0.0);
        divide( p1 , p2 , 1 );
        g << cod << '\n';
        --T;
	}
	g.close();
}