解いた問題

7/03/2012

SRM412 Div2 Medium

500

やるだけ



  1. class BirthdayReminders {  
  2. public:  
  3.   vector <string> remind(vector <string> friendNames, vector <int> birthDates, int currentDate, vector <string> occasions, vector <int> days, int k)  
  4.   {  
  5.     vector< vector<int> > v;  
  6.   
  7.     const int N = friendNames.size();  
  8.     const int M = occasions.size();  
  9.   
  10.     for (int i = 0; i < N; ++i) {  
  11.       for (int j = 0; j < M; ++j) {  
  12.         int m = currentDate - birthDates[i];  
  13.         int n = m / days[j] + (bool)(m % days[j]);  
  14.         for (int loop = 100; loop--; ++n) {  
  15.           int D = birthDates[i] + n * days[j];  
  16.           vector<int> u;  
  17.           u.push_back(D);  
  18.           u.push_back(j);  
  19.           u.push_back(i);  
  20.           u.push_back(n);  
  21.           v.push_back(u);  
  22.         }  
  23.       }  
  24.     }  
  25.   
  26.     sort(v.begin(), v.end());  
  27.     char buff[1000];  
  28.     vector<string> ret;  
  29.     for (int i = 0; i < k; ++i) {  
  30.       sprintf(buff, "%d. %s %s (%d)", v[i][0], friendNames[v[i][2]].c_str(), occasions[v[i][1]].c_str(), v[i][3]);  
  31.       ret.push_back(string(buff));  
  32.     }  
  33.     return ret;  
  34.   }  
  35. };