Git Product home page Git Product logo

Comments (2)

hyponet avatar hyponet commented on September 3, 2024

http://codeforces.com/contest/1197

from arts.

BLF2 avatar BLF2 commented on September 3, 2024

我就不新建Issues了,题目上面有了,思路是长度为L的梯子最多可以有L-1阶,因为梯子起码有两根竖着的木棍,L的大小就是这两根木棍中较短的那个长度,因为最下面接触地面的那一阶不需要,当然不仅仅是L-1就完事了,还要考虑你有没有L-1根木棍,于是答案就是木棍数N-2(梯子竖着的木棍是两根,要减掉)和L-1取最小,即min(L-1,n-2),java代码:
`import java.util.Arrays;
import java.util.Scanner;

public class Solution {

public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int t = sc.nextInt();
    for (int i = 0; i < t; i++) {
        int n = sc.nextInt();

        int arrays[] = new int[n];
        for (int j = 0; j < n; j++) {
            arrays[j] = sc.nextInt();

        }
        Arrays.sort(arrays);
        int value = n - 2 < arrays[arrays.length - 2] - 1 ? n - 2 : arrays[arrays.length - 2] - 1;
        System.out.println(value < 0 ? 0 : value);

    }
}

}
`
代码还有优化的地方:最开始没注意N和L的范围,考虑了小于0的情况,其实用范围估算,是不会小于0的。

from arts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.