http://acm.hdu.edu.cn/showproblem.php?pid=1008
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 4 seconds to move down one floor. The elevator will stay for 5 seconds at each stop.
For a given request list, you are to compute the total time spent to fulfill the requests on the list. The elevator is on the 0th floor at the beginning and does not have to return to the ground floor when the requests are fulfilled.
上面是地址,下午看了好一会,问人再做完的。
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- int now,sum,n,i,;
- while(1)
- {
- int floor[100]={0};
- sum=0;
- now=0;
- sum=0;
- scanf("%d",&n); /*输入数字的个数*/
- if(n==0) /*如果等于0则退出*/
- {
- break;
- }
- for(i=0;i<n;i++)
- {
- scanf("%d",&floor[i]); /*输入楼梯的阶数*/
- }
- for(i=0;i<n;i++)
- {
- if (floor[i]>now) /*如果是上楼则执行*/
- {
- sum +=(floor[i]-now)*6;
- }
- else
- {
- sum +=(now-floor[i])*4; /*下楼执行的语句*/
- }
- now=floor[i];
- }
- printf("%d",sum+n*5); /*最后要加上停留的5秒*/
- }
- system("pause");
- return 0;
- }