Pagini recente » Cod sursa (job #1818819) | Cod sursa (job #2660393) | Cod sursa (job #2622289) | Cod sursa (job #497311) | Cod sursa (job #2119360)
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
ifstream fin("reuniune.in");
ofstream fout("reuniune.out");
class dreptunghi{
public:
int x1, x2, y1, y2, valid;
inline long long aria(void);
inline long long perimetru(void);
};
inline long long dreptunghi::aria(){
return (1LL * dreptunghi::valid * abs(dreptunghi::x1 - dreptunghi::x2) * abs(dreptunghi::y1 - dreptunghi::y2));
}
inline long long dreptunghi::perimetru(){
return (2LL * dreptunghi::valid * (abs(dreptunghi::x1 - dreptunghi::x2) + abs(dreptunghi::y1 - dreptunghi::y2)));
}
dreptunghi intersectie(dreptunghi d1, dreptunghi d2){
dreptunghi i;
i.x1 = min(d1.x1, d2.x1);
i.x2 = max(d1.x2, d2.x2);
i.y1 = min(d1.y1, d2.y1);
i.y2 = max(d1.y2, d2.y2);
i.valid = 0;
if((d1.x1 <= d2.x1 and d1.x1 >= d2.x2) or (d1.x2 <= d2.x1 and d1.x2 >= d2.x2))
if((d1.y1 <= d2.y1 and d1.y1 >= d2.y2) or (d1.y2 <= d2.y1 and d1.y2 >= d2.y2))
if(d1.valid and d2.valid)
i.valid = 1;
if((d2.x1 <= d1.x1 and d2.x1 >= d1.x2) or (d2.x2 <= d1.x1 and d2.x2 >= d1.x2))
if((d2.y1 <= d1.y1 and d2.y1 >= d1.y2) or (d2.y2 <= d1.y1 and d2.y2 >= d1.y2))
if(d1.valid and d2.valid)
i.valid = 1;
return i;
}
dreptunghi a, b, c, ab, bc, ac, abc;
long long aria, perimetru;
int main(){
fin >> a.x2 >> a.y2 >> a.x1 >> a.y1;
fin >> b.x2 >> b.y2 >> b.x1 >> b.y1;
fin >> c.x2 >> c.y2 >> c.x1 >> c.y1;
a.valid = b.valid = c.valid = 1;
ab = intersectie(a, b);
bc = intersectie(b, c);
ac = intersectie(a, c);
abc = intersectie(ab, c);
aria = a.aria() + b.aria() + c.aria() + abc.aria() - ab.aria() - bc.aria() - ac.aria();
perimetru = a.perimetru() + b.perimetru() + c.perimetru() + abc.perimetru() - ab.perimetru() - bc.perimetru() - ac.perimetru();
cout << aria << ' ' << perimetru;
fout << aria << ' ' << perimetru;
return 0;
}