Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <set>
- #include <vector>
- #include <map>
- using namespace std;
- int find_chapter(int X, int Y) {
- if (X >= 0) {
- if (Y >= 0) {
- return 1;
- } else {
- return 4;
- }
- } else {
- if (Y >= 0) {
- return 2;
- } else {
- return 3;
- }
- }
- }
- struct coordinate {
- int X;
- int Y;
- int chapter;
- int distance = 0;
- int find_distance() {
- if (this->X != 0 && this->Y != 0) {
- distance = min(abs(this->X), abs(this->Y));
- }
- }
- void set_X(int X) {
- this->X = X;
- chapter = find_chapter(X, Y);
- distance = find_distance();
- }
- void set_Y(int Y) {
- this->Y = Y;
- chapter = find_chapter(X, Y);
- distance = find_distance();
- }
- int get_X() const{
- return X;
- }
- int get_Y() const{
- return Y;
- }
- int get_Chapter() const{
- return chapter;
- }
- int get_Distance() const {
- return distance;
- }
- };
- vector<coordinate> coordinates;
- coordinate ULTIMATE_COORDINATE_JAJAJA;
- int find_Nearest_Distance(int chapter) {
- int Min_Distance = 0;
- for (const auto &coordinate : coordinates) {
- if (coordinate.get_Chapter() == chapter) {
- if (Min_Distance == 0) {
- Min_Distance = coordinate.get_Distance();
- continue;
- }
- if (Min_Distance > coordinate.get_Distance()) {
- Min_Distance = coordinate.get_Distance();
- ULTIMATE_COORDINATE_JAJAJA = coordinate;
- }
- }
- }
- return Min_Distance;
- }
- int main() {
- int N = 0, X = 0, Y = 0, buffer_value = -1, max_quarter = 0;
- coordinate temp_coor;
- cin >> N;
- map<int, int> quarters;
- for (int i = 0; i < N; i++) {
- cin >> X >> Y;
- temp_coor.set_X(X);
- temp_coor.set_Y(Y);
- coordinates.push_back(temp_coor);
- quarters[temp_coor.get_Chapter()]++;
- }
- for (const auto&[chapter, value] : quarters) {
- if (value > buffer_value) {
- buffer_value = value;
- max_quarter = chapter;
- } else if (value == buffer_value) {
- max_quarter = (find_Nearest_Distance(max_quarter) < find_Nearest_Distance(chapter)) ? max_quarter : chapter;
- }
- }
- cout << "K = " << max_quarter << "\nM = " << buffer_value << "\nA = (" << ULTIMATE_COORDINATE_JAJAJA.get_X() <<
- "," << ULTIMATE_COORDINATE_JAJAJA.get_Y() << ")\n"<< "R = " << ULTIMATE_COORDINATE_JAJAJA.get_Distance();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement