首页 > 其他分享 >PAT 甲级1008【1008 Elevator】

PAT 甲级1008【1008 Elevator】

时间:2023-10-23 20:27:02浏览次数:38  
标签:PAT java int sum Elevator next io 1008 last

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;

public class Main {
    @SuppressWarnings("unchecked")
    public static void main(String[] args) throws IOException {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        in.nextToken();
        int n = (int) in.nval;
        int last = 0;
        int sum = 0;
        for (int i = 0; i < n; i++) {
            in.nextToken();
            int next = (int) in.nval;
            if (next > last) {
                sum += 6 * (next - last);
                sum += 5;
                last = next;
            } else {
                sum += 4*(last - next);
                sum += 5;
                last = next;
            }
        }
        System.out.println(sum);
    }
}

 

标签:PAT,java,int,sum,Elevator,next,io,1008,last
From: https://www.cnblogs.com/fishcanfly/p/17783347.html

相关文章

  • xpath的contains用法
    xpath('//div[contains(@class,"a")andcontains(@class,"b")]')#它会取class含有有a和b的元素xpath('//div[contains(@class,"a")orcontains(@class,"b")]')#它会取class含有a或者b满足时,或者同时满足时的元素starts-with顾名思义,匹......
  • PAT 甲级【1007 Maximum Subsequence Sum】
    本题是考察动态规划与java的快速输入:max[i]表示第i个结尾的最大的连续子串和。bbegin[i]表示第[begin[i],i]为最大和的开始位置超时代码:importjava.io.BufferedReader;importjava.io.IOException;importjava.io.InputStreamReader;publicclassMain{@Suppres......
  • OSPF(Open Shortest Path First)vlink-peer
    配置流程1)系统视图下启用ipv6ipv62)创建ospfv3进程ospfv3100//进程为100router-id1.1.1.1//唯一标识为1.1.1.13)配置端口#interfaceGigabitEthernet0/0/1ipv6enable ipv6address2023:23::2/64 ipv6addressautolink-localospfv3100area0.0.0.1//将接口划分......
  • PAT_A1044 Shopping in Mars
    ShoppinginMarsisquiteadifferentexperience.TheMarspeoplepaybychaineddiamonds.Eachdiamondhasavalue(inMarsdollarsM$).Whenmakingthepayment,thechaincanbecutatanypositionforonlyonceandsomeofthediamondsaretakenoffth......
  • 多路径multipath共享磁盘配置
    1. 配置共享磁盘1.1. 主机关机的情况下,添加4块硬盘,每块磁盘设置如下  1.2. 另外一台主机添加上面已经存在的磁盘,同样设置 1.3. 修改两台虚拟机的配置文件(.vmx)disk.locking="FALSE"disk.EnableUUID="TRUE"scsi1:1.SharedBus="Virtual"......
  • 内核文档翻译(chatgpt) —— Pathname lookup (路径名查找)
    原文:https://www.kernel.org/doc/html/latest/filesystems/path-lookup.html内核中文件系统相关的文档汇总:FilesystemsintheLinuxkernelThiswrite-upisbasedonthreearticlespublishedatlwn.net:PathnamelookupinLinuxRCU-walk:fasterpathnamelookupinLi......
  • c: Visitor Pattern
     /***@filevalidator.h*@authoryourname([email protected])*@brief观察者模式VisitorPattern来源:C现代编程集成开发环境、设计模式、极限编程、测试驱动开发、重构、持续集成日.花井志生著,杨文轩译,人民邮电出版社*@version0.1*@date2023-10-21......
  • 动态加载目录进classpath
    参考文档:https://www.codelast.com/%E5%8E%9F%E5%88%9B-java%E5%8A%A8%E6%80%81%E6%B7%BB%E5%8A%A0%E4%B8%80%E4%B8%AA%E7%9B%AE%E5%BD%95%E5%88%B0classpath%E4%B8%AD/ publicstaticloadFoldertoClasspath(){FileprogramRootDir=newFile("./");URL......
  • PAT_A 1010 Radix
    Givenapairofpositiveintegers,forexample,6and110,canthisequation6=110betrue?Theansweris yes,if6isadecimalnumberand110isabinarynumber.Nowforanypairofpositiveintegers N1​ and N2​,yourtaskistofindtheradixofon......
  • 【愚公系列】2023年10月 二十三种设计模式(十九)-观察者模式(Observer Pattern)
    ......