某公共汽车线路上共有15个站(包括起点和终点站).在每个站上车的人中,恰好在以后各站分别下去一个.要使行驶过程中每位乘客均有座位,车上至少备有多少个座位供乘客使用?
// 因为第一站上 14个 后边每个站才能下一个 同理第二站要上13个
//以此类推 下车则是 第二站下一个 第三站下2个
#include<iostream>
using std::cout;
int main()
{
int get_on,get_off;
int max,current;
max = current = 0;
for (get_on = 14,get_off = 0 ; get_off < 15 ; get_on--,get_off++)
{
current += get_on - get_off; //
if (max < current) max = current;
}
cout << "最多要准备" << max << "个座位!\n";
return 0;
}
åé¢å¯ä»¥æ³¨éä¸ä¹ï¼
追çè¿éçC++ä¸Cè¯è¨çåºå«å¨äºï¼æå°çè¯å¥ä¸ä¸æ ·ã
å
¶ä»é»è¾ä¸åã