解题思路:
注意事项:
参考代码:
import java.util.Scanner; public class T1456 { public static int find(int []a) { int ans=0,n=a.length-1; int i,j; for(i=1;i<=n;i++) { int max=a[i],min=a[i]; for(j=i;j<=n;j++) { max=a[j]>max?a[j]:max; min=a[j]<min?a[j]:min; if(max-min == j-i) ans++; } } return ans; } public static void main(String[] args) { Scanner in = new Scanner(System.in); while(in.hasNext()) { int n = in.nextInt(); int []a = new int[n+1]; for(int i = 1;i<=n;i++) a[i] = in.nextInt(); int ans = find(a); System.out.println(ans); } in.close(); } }
0.0分
0 人评分