From f279107065146a4940f5e73602a1c3c09e58b31d Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Sun, 18 Oct 2020 18:56:43 +0200 Subject: chore: name of first year folder --- 1_anno/Programmazione_2/coding_contest/ladri.cpp | 53 ++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 1_anno/Programmazione_2/coding_contest/ladri.cpp (limited to '1_anno/Programmazione_2/coding_contest/ladri.cpp') diff --git a/1_anno/Programmazione_2/coding_contest/ladri.cpp b/1_anno/Programmazione_2/coding_contest/ladri.cpp new file mode 100644 index 0000000..04e8e65 --- /dev/null +++ b/1_anno/Programmazione_2/coding_contest/ladri.cpp @@ -0,0 +1,53 @@ +#include +#include +#include + +using namespace std; + +int main() { + ifstream in("input.txt"); + ofstream out("output.txt"); + + for(short _ = 0; _ < 100; ++_) { + int N, K, M; + in >> N >> K >> M; + int* path = new int[N+1]; + int i; + for(i = 0; i < N; ++i) + in >> path[i]; + + path[i] = M; + int start = 0; + vector values; + /* 1 31 33 38 62 69 93 97 98 99 */ + /* x x x x x x + * K = 30 + */ + for(int i = 0; i < N+1; ++i) { + if(path[i] - start > K) { + for(int j = i-1; j >= 0; --j) { + if(path[i] - path[j] <= K) { + values.push_back(path[j]); + start = path[j]; + i = j; + break; + } + } + } + } + + // Stampa la path corretta per debug + for(auto const& i: values) + cout << i << ' '; + + cout << endl; + out << values.size() << endl; + delete[] path; + } + + + out.close(); + in.close(); + + return 0; +} -- cgit v1.2.3-18-g5258