【京东】题目死长死长的那个小山烽火台题



package com.company;


import java.util.Scanner;

public class Main {
    public static boolean canSee1(int[] a, int x, int y) {
        int len = a.length;
        boolean ret = true;
        for (int i = x + 1; i < y; i++) {
            if (a[i] > a[x] || a[i] > a[y]) {
                ret = false;
                break;
            }
        }

        return ret;
    }

    public static boolean canSee2(int[] a, int x, int y) {
        int len = a.length;
        boolean ret = true;
        for (int i = y + 1; i < len ; i++) {
            if (a[i] > a[x] || a[i] > a[y]) {
                ret = false;
                break;
            }
        }
        for (int i = 0; i < x; i++) {
            if (a[i] > a[x] || a[i] > a[y]) {
                ret = false;
                break;
            }
        }
        return ret;
    }

    public static void main(String[] args) {
        // write your code here
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextInt()) {
            int n = scanner.nextInt();
            int[] h = new int[n];
            int count = 0;
            for (int i = 0; i < n; i++) {
                h[i] = scanner.nextInt();
            }
            for (int i = 0; i < n - 1; i++) {
                for (int j = i + 1; j < n; j++) {
                    if (canSee1(h, i, j) || canSee2(h, i, j)) {
                        count++;
                    }

                }
            }
            System.out.println(count);

        }
    }
}
我特么以为9点10分交卷,没有提交上代码。。。。。真是头号大**。。。。。。大家帮我Review一下代码呗
全部评论
http://codeforces.com/contest/5/problem/E 原题
点赞 回复 分享
发布于 2016-09-05 22:42
这排版。。。
点赞 回复 分享
发布于 2016-09-05 22:15
你还记得给的测试数据吗?有的话给我呗!谢谢啊!
点赞 回复 分享
发布于 2016-09-05 22:28

相关推荐

03-27 15:39
算法工程师
几乎所有大中厂都挂了,现在压力拉满了。。。
ohs的小木屋:我摆了,该投投该面面,就当给自己找事做了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务