Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <climits>
- #include <cmath>
- #include <utility>
- struct Okrag
- {
- int x;
- int y;
- int r;
- };
- // Czy okrag o1 zawiera sie w o2
- bool czyNalezy(Okrag o1, Okrag o2)
- {
- // Rownanie o2
- // (x - o2.x)^2 - (x - o2.y) ^ 2 = o2.r^2
- return pow(o1.x - o2.x, 2) + pow(o1.y - o2.y, 2) <= pow(o2.r, 2);
- }
- bool warunek(Okrag o1, Okrag o2)
- {
- bool w1 = pow(o1.r + o2.r, 2) == pow(o1.x - o2.x, 2) + pow(o1.y - o2.y, 2);
- bool w2 = pow(o1.r - o2.r, 2) == pow(o1.x - o2.x, 2) + pow(o1.y - o2.y, 2);
- return w1 || w2;
- }
- int main()
- {
- std::vector<Okrag> tab;
- std::ifstream dane("dane.txt");
- unsigned int N = 100;
- for(int i = 0; i < N; i++)
- {
- Okrag tmp;
- dane >> tmp.x;
- dane >> tmp.y;
- dane >> tmp.r;
- tab.emplace_back(tmp);
- }
- Okrag o1;
- o1.r = INT_MAX;
- o1.x = 0;
- o1.y = 0;
- std::vector<Okrag> maleR;
- for (auto &temp : tab)
- {
- if (temp.r < o1.r)
- {
- o1 = temp;
- maleR.clear();
- }
- if (temp.r == o1.r)
- maleR.emplace_back(temp);
- }
- // 4.1
- std::ofstream wynik1("wynik1.txt");
- for (auto &okrag : maleR)
- wynik1 << okrag.x << " " << okrag.x << " " << okrag.r << std::endl;
- wynik1 << maleR.size();
- // 4.2
- std::ofstream wynik2("wynik2.txt");
- int ile_srodkow = 0;
- int max_srodkow = INT_MIN;
- Okrag maxokrag;
- for (auto &okrag : tab)
- {
- for (auto &test : tab)
- {
- if (czyNalezy(test, okrag))
- ile_srodkow++;
- }
- if (ile_srodkow > max_srodkow)
- {
- maxokrag = okrag;
- max_srodkow = ile_srodkow;
- }
- ile_srodkow = 0;
- }
- // max_srodkow - 1 bo sprawdzam kazdy a kazdym, a nie kazdy z kolejnym
- wynik2 << maxokrag.x << " " << maxokrag.y << " " << maxokrag.r << std::endl;
- wynik2 << max_srodkow - 1;
- // 4.3
- std::ofstream wynik3("wynik3.txt");
- int ile_par = 0;
- std::vector<std::pair<Okrag, Okrag>> pary;
- for (int i = 0; i < tab.size(); i++)
- {
- for (int j = i + 1; j < tab.size(); j++)
- {
- if (warunek(tab[i], tab[j]))
- {
- ile_par += 2;
- pary.emplace_back(tab[i], tab[j]);
- pary.emplace_back(tab[i], tab[j]);
- }
- }
- }
- wynik3 << ile_par << std::endl;
- for (auto ¶ : pary)
- {
- wynik3 << para.first.x << " " << para.first.y << " " << para.first.r << " ";
- wynik3 << para.second.x << " " << para.second.y << " " << para.second.r << std::endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement