Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.30 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <unordered_set>
  4. #include <set>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. struct Book {
  10.   unsigned int score;
  11.   unsigned int id;
  12. };
  13.  
  14. // For Hash Map
  15. struct Hash {
  16.   size_t operator() (const Book &book) const {
  17.     return size_t(book.id) ^ size_t(book.score);
  18.   }
  19. };
  20.  
  21. inline bool operator == (Book const& lhs, Book const& rhs)
  22. {
  23.   return (lhs.id == rhs.id) && (lhs.score == rhs.score);
  24. }
  25.  
  26. struct Library {
  27.   unsigned int tts; // How many days do signup process takes
  28.   unsigned int bpd; // Books per day
  29.   unsigned int score; // Avg books the lib can send
  30.   unsigned int id; // id of library which came from the input
  31. };
  32.  
  33.  
  34. using veci = std::vector<int>;
  35. using vecb = std::vector<Book>;
  36. using veclib = std::vector<Library>;
  37.  
  38. std::vector<veci> booksPerLib;
  39. vecb books;
  40. veclib libraries;
  41. std::unordered_set<Book, Hash> sentBooks;
  42. int D; // Days for scanning
  43.  
  44.  
  45. void sortLibraries(veclib &vec) {
  46.   std::sort(libraries.begin(), libraries.end(),
  47.             [](const Library &a, const Library &b) -> bool {
  48.               return a.score > b.score;
  49.             });
  50.  
  51. }
  52.  
  53. int main(int argc, char **argv) {
  54.   int bookCount, libraryCount;
  55.   cin >> bookCount >> libraryCount >> D;
  56.  
  57.   books.resize(bookCount);
  58.   for (size_t i = 0; i < bookCount; ++i)
  59.   {
  60.     cin >> books[i].score;
  61.     books[i].id = i;
  62.   }
  63.  
  64.   // Sort the global Books array
  65.   // std::sort(books.begin(), books.end(),
  66.   //           [](const Book& a, const Book& b) -> bool
  67.   //           {
  68.   //             return a.score > b.score;
  69.   //           });
  70.  
  71.  
  72.   // Input libraries and their respective books
  73.   libraries.resize(libraryCount);
  74.   booksPerLib.resize(libraryCount);
  75.   int libraryBookCount, signupDays, booksPerDay;
  76.   for (size_t i = 0; i < libraryCount; ++i)
  77.   {
  78.     cin >> libraryBookCount >> signupDays >> booksPerDay;
  79.     booksPerLib[i].resize(libraryBookCount);
  80.  
  81.     int thisLibSumBookScore = 0;
  82.     for (size_t j = 0; j < libraryBookCount; ++j)
  83.     {
  84.       cin >> booksPerLib[i][j];
  85.       thisLibSumBookScore += books[booksPerLib[i][j]].score;
  86.     }
  87.  
  88.     libraries[i].bpd = booksPerDay;
  89.     libraries[i].tts = signupDays;
  90.     libraries[i].score = (D - signupDays) * (thisLibSumBookScore / booksPerDay);
  91.     libraries[i].id = i;
  92.   }
  93.  
  94.   return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement