题目链接:https://vjudge.net/problem/Aizu-ALDS1_3_B
1 #include<iostream> 2 #include<string> 3 #include<queue> 4 #include<algorithm> 5 using namespace std; 6 7 int main() 8 { 9 int n, q, t; 10 string name; 11 queue< pair< string, int > > Q; 12 cin >> n >> q; 13 14 for( int i = 0;i < n;i++ ) 15 { 16 cin >> name >> t; 17 Q.push(make_pair(name, t)); 18 } 19 20 pair<string, int> u; 21 int elaps = 0, a; 22 23 //模拟 24 while( !Q.empty() ) 25 { 26 u = Q.front() ;Q.pop() ; 27 a = min (u.second , q); 28 u.second -= a; 29 elaps += a; 30 if(u.second > 0) 31 { 32 Q.push(u); 33 }else 34 { 35 cout << u.first <<" "<<elaps<<endl; 36 } 37 } 38 return 0; 39 }