Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

要疯了,看了两个小时就是找不到错误

Posted by 3016226031 at 2021-11-23 23:39:38
2833题目,java的解法,看不懂自己哪里写错了,求救

import java.util.*;
import java.text.DecimalFormat;

public class Main {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()){
            int n_1 = sc.nextInt();
            int log_1 = n_1;
            int n_2 = sc.nextInt();
            int log_2 = n_2;
            int n = sc.nextInt();
            if (n_1 == 0 || n_2 == 0 || n == 0){
                sc.close();
                break;
            }
            PriorityQueue<Long> queue_1 = new PriorityQueue<Long>(15); // 最小堆
            PriorityQueue<Long> queue_2 = new PriorityQueue<Long>(15, new Comparator<Long>() {
                @Override
                public int compare(Long o1, Long o2) {
                    return (int)(o2 - o1);
                }
            }); // 最大堆
            double sum = 0;
            int count = 0;
            while (count++ < n){
                long num = sc.nextLong();
                sum += num;
                if (queue_1.size() <= 10 || queue_1.peek() < num){
                    queue_1.add(num);
                }
                if (queue_2.size() <= 10 || queue_2.poll() > num){
                    queue_2.add(num);
                }
                if (queue_1.size() > 10){
                    queue_1.poll();
                }
                if (queue_2.size() > 10){
                    queue_2.poll();
                }
            }
            while(n_1-- > 0){
                sum -= queue_2.poll();
            }
            while(n_2-- > 0){
                sum -= queue_1.poll();
            }
            DecimalFormat df1 = new DecimalFormat();
            String style = "0.000000";
            df1.applyPattern(style);
            System.out.println(df1.format(sum / (n - log_1 - log_2)));
        }
    }
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator