// Mateusz Bogusławski #include <iostream> using namespace std; #define L_MIN -1000000 #define L_MAX 1000000 int main() { int n, cs = 0, cg = 0; cin >> n; int ps, pg, ls, lg; cin >> ls; lg = ls; for (int i = 1; i < n; i++) { ps = ls; pg = lg; cin >> ls; lg = ls; if (i%2 == 1) { if (ls >= ps) { cs++; ls = L_MIN; } if (lg <= pg) { cg++; lg = L_MAX; } } else { if (ls <= ps) { cs++; ls = L_MAX; } if (lg >= pg) { cg++; lg = L_MIN; } } } cout << min(cs , cg) << endl; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | // Mateusz Bogusławski #include <iostream> using namespace std; #define L_MIN -1000000 #define L_MAX 1000000 int main() { int n, cs = 0, cg = 0; cin >> n; int ps, pg, ls, lg; cin >> ls; lg = ls; for (int i = 1; i < n; i++) { ps = ls; pg = lg; cin >> ls; lg = ls; if (i%2 == 1) { if (ls >= ps) { cs++; ls = L_MIN; } if (lg <= pg) { cg++; lg = L_MAX; } } else { if (ls <= ps) { cs++; ls = L_MAX; } if (lg >= pg) { cg++; lg = L_MIN; } } } cout << min(cs , cg) << endl; } |