• Thanos Sort


    题目链接:http://codeforces.com/contest/1145/problem/A

    愚人节题目,求最长不下降连续序列,序列还得是去一半,去一半得到的。

    递归

     1 import java.util.Scanner;
     2 
     3 public class pro1145A {
     4 
     5     public static int rise(int[] R,int ind,int len){
     6         if(len==1) return 1;
     7         boolean flag = true;
     8         for(int i=ind;i<ind+len-1;++i){
     9             if(R[i]>R[i+1]){
    10                 flag = false;
    11                 break;
    12             }
    13         }
    14         if(flag)
    15             return len;
    16         else{
    17             return Math.max(rise(R,ind,len/2),rise(R,ind+len/2,len/2));
    18         }
    19     }
    20 
    21     public static void main(String[] args){
    22         Scanner input = new Scanner(System.in);
    23 
    24         int N;
    25         N = input.nextInt();
    26 
    27         int[] raw = new int[N];
    28         for(int i=0;i<N;++i){
    29             raw[i] = input.nextInt();
    30         }
    31 
    32         int ans = rise(raw,0,N);
    33         System.out.println(ans);
    34     }
    35 }
    View Code

    分治

     1 package com.jetbrains;
     2 
     3 import java.util.Scanner;
     4 
     5 public class pro1145A {
     6 
     7     public static int rise(int[] arr,int L,int R){
     8         if(L + 1 == R) return 1;
     9 
    10         int mid = L+(R-L)/2;
    11         int Lans = rise(arr,L,mid),
    12             Rans = rise(arr,mid,R);
    13 
    14         if(arr[mid-1] <= arr[mid]&& Lans == mid-L
    15                 && Rans == R-mid)
    16             return  Lans+Rans;
    17         else
    18             return Math.max(Lans,Rans);
    19     }
    20 
    21     public static void main(String[] args){
    22         Scanner input = new Scanner(System.in);
    23 
    24         int N;
    25         N = input.nextInt();
    26 
    27         int[] raw = new int[N];
    28         for(int i=0;i<N;++i){
    29             raw[i] = input.nextInt();
    30         }
    31 
    32         int ans = rise(raw,0,N);
    33         System.out.println(ans);
    34     }
    35 }
    View Code
  • 相关阅读:
    vim 字符串替换整理
    Linux Server release 7.3 更换阿里网络yum源
    VMware Vsphere 6.0安装部署 Vsphere ESXi安装
    VMware Vsphere 6.0安装部署 总体部署架构
    vsphere client和vsphere web client的区别
    VMware Vsphere 6.0安装部署 vCenter Server安装
    Python的正则表达概述
    centos的dns配置总结
    linux系统下的/proc目录介绍
    linux基础命令学习总结
  • 原文地址:https://www.cnblogs.com/Kiritsugu/p/11075015.html
Copyright © 2020-2023  润新知