PAT:1008. Elevator (20) AC

#include<stdio.h>

int main()
{
  int n,ans=0,now=0;        //要停n层,ans是总时间,now代表当前层数
  scanf("%d",&n);
  for(int i=0 ; i<n ; ++i)
  {
    int tmp;
    scanf("%d",&tmp);
    if(tmp>now)          //上楼,每上一层6秒
    {
      ans+=(tmp-now)*6;
      now=tmp;
    }
    else if(tmp<now)      //下楼,每下一层4秒
    {
      ans+=(now-tmp)*4;
      now=tmp;
    }
    ans+=5;            //不上也不下——停留,每次5秒;上楼或者下楼,也要停5秒。和在一起写了
  }
  printf("%d",ans);
  return 0;
}
时间: 2024-10-07 08:51:34

PAT:1008. Elevator (20) AC的相关文章

[PTA] PAT(A) 1008 Elevator (20 分)

目录 Problem Description Input Output Sample Sample Input Sample Output Solution Analysis Code Problem portal: 1008 Elevator (20 分) Description  The highest building in our city has only one elevator. A request list is made up with $N$ positive numbers

PAT:1035. Password (20) AC

#include<stdio.h> #include<string.h> typedef struct STU { char mID[15]; char mpass[15]; bool tag; }STU; STU arr[1010]; int main() { memset(arr,0,sizeof(arr)); int n,change=0; scanf("%d",&n); for(int i=0 ; i<n ; ++i) { scanf(&q

PAT:1077. Kuchiguse (20) AC

#include<stdio.h> #include<string.h> char in[100][260]; int main() { int n,lenMIN=260; scanf("%d",&n); getchar(); //[skill]吸收换行符 for(int i=0 ; i<n ; ++i) { gets(in[i]); int len=strlen(in[i]); if(len<lenMIN) lenMIN=len; for(

1008. Elevator (20)——PAT (Advanced Level) Practise

题目信息: 1008. Elevator (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator w

Programming Ability Test学习 1008. Elevator (20)

1008. Elevator (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will st

1008 Elevator (20分)

1008 Elevator (20分) 题目: The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator

【PAT甲级】1008 Elevator (20分)

1008 Elevator 题目: The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one

PAT:1008. 数组元素循环右移问题 (20) AC

#include<stdio.h> #include<stdlib.h> int main() { int n,move,cnt=0; scanf("%d%d",&n,&move); int* arr; arr=(int*)calloc(n,sizeof(int)); for(int i=0 ; i<n ; ++i) scanf("%d",&arr[i]); move%=n; //取余可以保证最多移动一轮 for

PAT (Advanced Level) Practise:1008. Elevator

[题目链接] The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and