[CodeVS 3289]花匠
转载请注明出处:http://danihao123.is-programmer.com/
这破题吃枣药丸……
这题略加思索,就能发现最优策略是找转折点。但需要注意相等连块中也会存在转折点……并且,n<3时不要搬走花!
代码:
#include <cstdio>
const int maxn=100001;
int A[maxn];
int main(){
int n;
bool flag=false,tal;
register int i,ans=0;
scanf("%d",&n);
if(n<3){
printf("%d\n",n);
return 0;
}
for(i=1;i<=n;i++){
scanf("%d",&A[i]);
}
for(i=1;i<=n;i++){
if(i==1){
ans++;
continue;
}
if(A[i]!=A[i-1])
flag=true;
if(i==n){
if(flag)
ans++;
break;
}
if(A[i]==A[i-1] && i>=2)
A[i-1]=A[i-2];
if((A[i]>A[i-1] && A[i]>A[i+1]) ||
(A[i]<A[i-1] && A[i]<A[i+1]))
ans++;
}
printf("%d\n",ans);
return 0;
}
Jul 01, 2023 06:02:58 PM
writers who have come together for dedicated news coverage of latest happenings around the country.Our team comprises of professional writers & citizen question-paper.com journalists with diverse range of interest in Journalism who are passionate about publishing the Education Updates with transparency in general public interest.Our team comprises of professional writers & citizen journalists with diverse range of interest in Journalism who are passionate about publishing the Education Updates.
Jul 28, 2023 12:12:51 AM
La hora militar, también conocida como hora de 24 horas, es una forma de decir la hora utilizada por las fuerzas armadas y otras organizaciones. Es diferente del reloj normal de 12 horas que usa la mayoría de la gente. hora militar y hora normal En horario militar, el día se divide en 24 horas, a partir de la medianoche (00:00) y hasta la medianoche siguiente. Cada hora está representada por un número de dos dígitos del 00 al 23.