Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cstring>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <iostream>
  6. #include <cassert>
  7. #include <cmath>
  8. #include <string>
  9. #include <queue>
  10. #include <set>
  11. #include <map>
  12. #include <cstdlib>
  13. #include <fstream>
  14.  
  15. using namespace std;
  16.  
  17. struct connectionInfo {
  18. int cacheNumber;
  19. int latency;
  20. };
  21.  
  22. struct endPointInfo {
  23. int centerLat;
  24.  
  25. vector< connectionInfo > connections;
  26. };
  27.  
  28. struct requestInfo {
  29. int video;
  30. int endpoint;
  31. int requests;
  32. };
  33.  
  34. int videosCount;
  35. int endPointsCount;
  36. int requestsCount;
  37. int cachesCount;
  38. int cacheSize;
  39. vector<int> videoSizes;
  40. vector<endPointInfo> endPoints;
  41. vector<requestInfo> requests;
  42.  
  43. vector< vector<int> > cacheToVideo;
  44. vector< set<int> > videoToCache;
  45.  
  46. void readData( ifstream& input) {
  47. input >> videosCount >> endPointsCount >> requestsCount >> cachesCount >> cacheSize;
  48. for (int i = 0; i < videosCount; i++) {
  49. int videoSize;
  50. input >> videoSize;
  51. videoSizes.push_back(videoSize);
  52. }
  53. for (int i = 0; i < endPointsCount; i++) {
  54. endPointInfo info;
  55. int connectionsCount;
  56. input >> info.centerLat >> connectionsCount;
  57. for (int j = 0; j < connectionsCount; j++) {
  58. connectionInfo connection;
  59. input >> connection.cacheNumber >> connection.latency;
  60. info.connections.push_back(connection);
  61. }
  62. }
  63. for (int i = 0; i < requestsCount; i++) {
  64. requestInfo request;
  65. input >> request.video >> request.endpoint >> request.requests;
  66. requests.push_back(request);
  67. }
  68. }
  69.  
  70. void writeAnswer(ofstream &output) {
  71. int nonZero = 0;
  72. for (int j = 0; j < cacheToVideo.size(); j++) {
  73. if (cacheToVideo[j].size() == 0) {
  74. nonZero++;
  75. }
  76. }
  77. output << nonZero << endl;
  78. for (int i = 0; i < cacheToVideo.size(); i++) {
  79. if (cacheToVideo[i].size() != 0) {
  80. output << i << " ";
  81. for (int j = 0; j < cacheToVideo[i].size(); j++) {
  82. output << cacheToVideo[i][j] << " ";
  83. }
  84. output << endl;
  85. }
  86. }
  87. }
  88.  
  89. void calcVideoToCache() {
  90. videoToCache.assign(videosCount, std::set<int>());
  91. for (int i = 0; i < cacheToVideo.size(); i++) {
  92. for (int j = 0; j < cacheToVideo[i].size(); j++) {
  93. int video = cacheToVideo[i][j];
  94. videoToCache[video].insert(i);
  95. }
  96. }
  97. }
  98.  
  99. long long calculate() {
  100. calcVideoToCache();
  101. for (int i = 0; i < requestsCount; i++) {
  102. requestInfo& request = requests[i];
  103. int video = request.video;
  104. int endPoint = request.endpoint;
  105. int bestLat = endPoints[endPoint].centerLat;
  106. for (int j = 0; j < endPoints[endPoint].connections.size(); j++) {
  107. int cacheNumber = endPoints[endPoint].connections[j].cacheNumber;
  108. if (videoToCache[video].count(cacheNumber) > 0) {
  109.  
  110. }
  111. }
  112. }
  113. }
  114.  
  115. int main() {
  116. ios_base::sync_with_stdio(false);
  117. cin.tie(nullptr);
  118. cout.setf(ios::fixed);
  119. cout.precision(9);
  120. cerr.setf(ios::fixed);
  121. cerr.precision(3);
  122.  
  123. vector<string> files;
  124. files.push_back("kittens");
  125. files.push_back("me_at_the_zoo");
  126. files.push_back("trending_today");
  127. files.push_back("videos_worth_spreading");
  128.  
  129. for (int i = 0; i < files.size(); i++) {
  130. ifstream input;
  131. ofstream output;
  132. input.open(files[i] + ".in");
  133. output.open(files[i] + ".out");
  134. readData(input);
  135. }
  136. freopen("test.in", "r", stdin);
  137. freopen("test.out", "w", stdout);
  138.  
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement