2010年10月1日金曜日

PKU Judge Online 2017 Speed Limit

■2017 Speed Limit

□Problem
省略.

□Solution
省略.

□Code
  1. package p2017;  
  2.   
  3. import java.util.*;  
  4. import java.lang.*;  
  5. import java.math.*;  
  6. import java.io.*;  
  7.   
  8. import static java.lang.Math.*;  
  9. import static java.util.Arrays.*;  
  10.   
  11. // AC  
  12. public class Main{  
  13.   
  14.     Scanner sc=new Scanner(System.in);  
  15.   
  16.     final int INF=Integer.MAX_VALUE;  
  17.     final double EPS=1e-9;  
  18.   
  19.     void run(){  
  20.         for(;;){  
  21.             int n=sc.nextInt();  
  22.             if(n==-1)  
  23.                 break;  
  24.             int ph=0;  
  25.             int tot=0;  
  26.             for(int i=0; i<n; i++){  
  27.                 int v=sc.nextInt();  
  28.                 int h=sc.nextInt();  
  29.                 tot+=(h-ph)*v;  
  30.                 ph=h;  
  31.             }  
  32.             println(tot+" miles");  
  33.         }  
  34.     }  
  35.   
  36.     void print(String s){  
  37.         System.out.print(s);  
  38.     }  
  39.   
  40.     void println(String s){  
  41.         System.out.println(s);  
  42.     }  
  43.   
  44.     public static void main(String[] args){  
  45.         // System.setOut(new PrintStream(new BufferedOutputStream(System.out)));  
  46.         new Main().run();  
  47.     }  
  48. }  

0 件のコメント: