Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- double S(double a, double b, double c) {
- double p = (a + b + c) / 2;
- return sqrt(p*(p - a)*(p - b)*(p - c));
- }
- double R(double x1, double y1, double x2, double y2) {
- return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
- }
- int main() {
- int g, k, x, y, r, p = 0;
- double Ax = 400, Ay = 400, Bx = 606, By = 606, Cx = 812, Cy = 400, Dx = 606, Dy = 194;
- double AB, AC, BC, CD, AD, A0, B0, C0, D0, s, ss, s1, s2, s3, s4, s5;
- AB = R(Ax, Ay, Bx, By); AC = R(Ax, Ay, Cx, Cy);
- BC = R(Bx, By, Cx, Cy); CD = R(Cx, Cy, Dx, Dy);
- AD = R(Ax, Ay, Dx, Dy); s1 = 0; s2 = 0; s3 = 0;
- s = S(AB, BC, AC); ss = S(AC, AD, CD);
- cout << "\n Input X: "; cin >> x;
- cout << "\n Input Y: "; cin >> y;
- cout << "\n Input R: "; cin >> r;
- for (g = Ax; g<Bx; g++) {
- for (k = Cy; k<By; k++) {
- A0 = R(Ax, Ay, g, k); B0 = R(Bx, By, g, k);
- C0 = R(Cx, Cy, g, k); D0 = R(Dx, Dy, g, k);
- s1 = S(AB, B0, A0); s2 = S(BC, B0, C0); s3 = S(AC, C0, A0);
- s4 = S(CD, C0, D0); s5 = S(AD, A0, D0);
- if ((R(x, y, g, k) <= r*r && ((s == s1 + s2 + s3) || (ss == s3 + s4 + s5)))) { p++; }
- }
- }
- cout << p << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment