Fork me on GitHub

NYOJ题目125盗梦空间

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

 

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

posted @ 2016-09-22 00:10  CC11001100  阅读(428)  评论(0编辑  收藏  举报