NYOJ题目125盗梦空间

本文介绍了一种解决ACM竞赛中特定编程题目的方法,通过记录不同层级的停留时间,并将其转换为现实时间来计算总时间,使用BigDecimal确保计算过程中的精度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

-----------------------------------------

 

开始的时候打算每进入或退出一层就换算成那层的时间,然而WA了。

怒,干脆就来点暴力的,管你什么跟什么只要停留了就根据层次统一换算成现实时间,使用BigDecimal保证精度,AC。

 

AC代码:

 1 import java.math.BigDecimal;
 2 import java.util.Scanner;
 3 
 4 public class Main {
 5 
 6     public static void main(String[] args) {
 7         
 8         Scanner sc=new Scanner(System.in);
 9         
10         int times=Integer.parseInt(sc.nextLine());
11         while(times-->0){
12             BigDecimal ans=BigDecimal.ZERO;
13             int level=0;
14             int n=Integer.parseInt(sc.nextLine());
15             for(int i=0;i<n;i++){
16                 String command=sc.nextLine();
17                 if(command.startsWith("IN")){
18                     level++;
19                 }else if(command.startsWith("OUT")){
20                     level--;
21                 }else if(command.startsWith("STAY")){
22                     int stay=Integer.parseInt(command.substring(5,command.length()));
23                     ans=ans.add(BigDecimal.valueOf(stay*60).divide(BigDecimal.valueOf(Math.pow(20,level))));
24                 }
25             }
26             System.out.println(ans);
27         }
28     }
29     
30 }

 

题目来源: http://acm.nyist.net/JudgeOnline/problem.php?pid=125

转载于:https://www.cnblogs.com/cc11001100/p/5894688.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值