Your task is to calculate the length of their route.
The next line contains N integers, describing the situation of the shops. You can assume that the situations of the shops are non-negative integer and smaller than 2^30.
The last case is followed by a line containing one zero.
For each test case, print the length of their shopping route.
0
70
Explanation for the first sample: They park their car at shop 13; go to shop 24, 37 and 89 and finally return to shop 13. The total length is (24-13) + (37-24) + (89-37) + (89-13) = 152
挺水的题目,给n个位置,从最左端到最右端再回来,就是 (最大值-最小值)*2
设置的最小值要足够大啊,
我开始设置的0xffffff(六个f,结果WA了。。)
#include <iostream> using namespace std; int main() { long long n,i,temp,maxx,minn; while(cin>>n && n) { maxx=-1;minn=0xffffffff; for(i=0;i<n;++i) { cin>>temp; if(temp>maxx) maxx=temp; if(minn>temp) minn=temp; } cout<<(maxx-minn)*2<<endl; } return 0; }
山东省第一届ACM大学生程序设计竞赛(原题)—G—Shopping,布布扣,bubuko.com
山东省第一届ACM大学生程序设计竞赛(原题)—G—Shopping
原文:http://blog.csdn.net/lttree/article/details/23603217