首页 > 其他 > 详细

NYOJ题目125盗梦空间

时间:2016-09-22 01:17:32      阅读:306      评论:0      收藏:0      [点我收藏+]

技术分享

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

 

开始的时候打算每进入或退出一层就换算成那层的时间,然而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

NYOJ题目125盗梦空间

原文:http://www.cnblogs.com/cc11001100/p/5894688.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!