第一行:所有客户的平均等待时间(精确到小数点后2位)输入样例
3 1 3 2 1 3 5输出样例
1.33
使用了STL中的stack()进行简化,使用双栈求解,详解见注释。
#include//模拟银行排队问题 #include #include #include using namespace std; const int N = 10005; int main() { int n; std::ios::sync_with_stdio(false); queue m;//存储到来时间 queue t;//需要的时间 cin >> n; for (int i = 0; i < n; i++) { float fir, time; cin >> fir; m.push(fir); cin >> time; t.push(time); } float wait = 0;//等待时间 float fin = 0;//结束开始的时间 fin = m.front() + t.front(); m.pop(); t.pop();//从第一位顾客结束末尾时间算起 while (!m.empty() && !t.empty()) { if (fin > m.front())//如果结束时间大于下一位顾客到来的时间 { wait += fin - m.front();//等待时间加上二者时间差 } else if(fin



