第一题,合唱队 import java.util.Scanner; public class Test {     public static void main(String[] args) {         Scanner sc=new Scanner(System.in);         int n = Integer.parseInt(sc.nextLine());         String[] h=sc.nextLine().split(" ");         int[] height=new int[h.length];         for(int i=0;i<n;i++){             height[i]=Integer.parseInt(h[i]);         }         int[] poses=new int[h.length];         int result=0;         for(int i =0;i<h.length;i++){             int pos=i;             for(int j=i+1;j<h.length;j++){                 if(height[i]>height[j]){                     pos=j;                 }             }             poses[i]=pos;         }         for(int i =0;i<h.length;i++){             if (poses[i]==i){                 result+=1;             }else{                 int start=i;                 int end=poses[i];                 for(int j=start;j<=end ;j++){                     if(poses[j]>end) end=poses[j];                 }                 result+=1;                 i=end;             }         }         System.out.println(result);     } }
点赞 评论

相关推荐

牛客网
牛客企业服务