【问题标题】:Runtime error on test 5 Codeforces Problem 158B - Taxi测试 5 Codeforces 问题 158B - 出租车上的运行时错误
【发布时间】:2022-06-16 22:19:13
【问题描述】:

在 Eclipse 或任何其他编译器中一切正常,但是当我在 Codeforces 158B 中提交它时,它在测试 5 中出现运行时错误。

import java.util.Scanner;
public class Taxi_B{

public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int n=sc.nextInt();
int []count= new int [n]; // New Array
int s=0;            //s is n inputs
for(int i=0;i<n;i++) {
    s=sc.nextInt(); //Taking n inputs
    count[s]++;     //count of s is count[s]++
}
int total = count[4] + count[3] + count[2] / 2; //4 is 1 group, 3 is one, 2 is one if divided by 2
count[1]-=count[3]; //count of 1 - count of three
if (count[2]%2==1) // if 2 is odd
{
    total+=1;   //total++
    count[1]-=2; //count of 1 -2
}
if (count[1] > 0) //if count of 1 is more than 0
{
    total+=(count[1]+3)/4; //total= total+(count of 1 +3)/4
}
System.out.println(total); //Sysout total;
sc.close();
} }

【问题讨论】:

  • 什么是测试 5 测试?您遇到了什么错误?
  • 代码应该做什么?它的输入是什么?所有需要的信息都应该在问题中。
  • 另外请说明您尝试实施的内容、您使用的测试数据以及预期的输出。

标签: java


最近更新 更多