#include <stdio.h> #include <string.h> int _max = 1000001; int arr[50000], arr2[50000]; int main() { int n, r = 0; scanf("%d", &n); int last = 0; for(int i=0;i<n;i++) scanf(" %d", arr + i); memcpy(arr2, arr, sizeof(arr)); int a1 = 0, a2 = 0; for(int i=1;i<n;i++) { int tmp = (i&1); if((tmp && arr2[i] >= arr2[i-1]) || (!tmp && arr2[i] <= arr2[i-1])) { arr2[i] = (tmp ? -1 : 1) * _max; a1++; } } /* for(int i=0;i<n;i++) printf("%d ", arr2[i]); putchar(10);*/ for(int i=1;i<n;i++) { int tmp = !(i&1); if((tmp && arr[i] >= arr[i-1]) || (!tmp && arr[i] <= arr[i-1])) { arr[i] = (tmp ? -1 : 1) * _max; a2++; } } //printf("%d %d\n", a1, a2); printf("%d\n", a1 < a2 ? a1 : a2); return 0; }
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 | #include <stdio.h> #include <string.h> int _max = 1000001; int arr[50000], arr2[50000]; int main() { int n, r = 0; scanf("%d", &n); int last = 0; for(int i=0;i<n;i++) scanf(" %d", arr + i); memcpy(arr2, arr, sizeof(arr)); int a1 = 0, a2 = 0; for(int i=1;i<n;i++) { int tmp = (i&1); if((tmp && arr2[i] >= arr2[i-1]) || (!tmp && arr2[i] <= arr2[i-1])) { arr2[i] = (tmp ? -1 : 1) * _max; a1++; } } /* for(int i=0;i<n;i++) printf("%d ", arr2[i]); putchar(10);*/ for(int i=1;i<n;i++) { int tmp = !(i&1); if((tmp && arr[i] >= arr[i-1]) || (!tmp && arr[i] <= arr[i-1])) { arr[i] = (tmp ? -1 : 1) * _max; a2++; } } //printf("%d %d\n", a1, a2); printf("%d\n", a1 < a2 ? a1 : a2); return 0; } |