171432025-05-24 19:53:26tomi7Háromszögeléscpp17Forditási hiba
#include <vector>
#include <algorithm>

extern int query(int x, int y);

int solve(int n) {
    std::vector<std::tuple<int, int, int>> diagonals;

    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            // kihagyjuk a szomszédos vagy azonos csúcsokat (nem átlók)
            if ((j - i + n) % n == 1 || (i - j + n) % n == 1 || i == j)
                continue;

            // távolság 0 csúcstól
            int left = std::min((i - 0 + n) % n, (j - 0 + n) % n);
            int right = std::min((0 - i + n) % n, (0 - j + n) % n);
            int d = std::max(left, right);

            diagonals.push_back({d, i, j});
        }
    }

    // növekvő távolság szerint rendezés
    std::sort(diagonals.begin(), diagonals.end());

    // lekérdezés legközelebbi átlóktól kezdve
    for (const auto& tup : diagonals) {
        int i = std::get<1>(tup);
        int j = std::get<2>(tup);
        if (query(i, j)) {
            return i * n + j;
        }
    }

    return -1; // elméletileg nem fordulhat elő, mindig van legalább 1 átló
}
Forditási hiba
open /var/local/lib/isolate/431/box/a.out: no such file or directory
main.cpp: In function 'int solve(int)':
main.cpp:20:32: error: no matching function for call to 'std::vector<std::tuple<int, int, int> >::push_back(<brace-enclosed initializer list>)'
   20 |             diagonals.push_back({d, i, j});
      |             ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
In file included from /usr/include/c++/12/vector:64,
                 from main.cpp:1:
/usr/include/c++/12/bits/stl_vector.h:1276:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >; value_type = std::tuple<int, int, int>]'
 1276 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/12/bits/stl_vector.h:1276:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<std::tuple<int, int, int> >::value_type&' {aka 'const std::tuple<int, int, int>&'}
 1276 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/12/bits/stl_vector.h:1293:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >; value_type = std::tuple<int, int, int>]'
 1293 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/12/bits/stl_vector.h:1293:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::tuple<int, int, int> >::value_type&&' {aka 'std::tuple<int, int, int>&&'}
 1293 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
main.cpp:29:28: error: no matching function for call to 'get<1>(const std::tuple<int, int, int>&)'
   29 |         int i = std::get<1>(tup);
      |                 ~~~~~~~~~~~^~~~~
In file included from /usr/include/c++/12/bits/stl_algobase.h:64,
                 from /usr/include/c++/12/vector:60:
/usr/include/c++/12...