Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 20th, 2010 | Syntax: C++ | Size: 1.60 KB | Hits: 68 | Expires: Never
Copy text to clipboard
  1. #include <iostream>
  2. #include <fstream>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <math.h>
  6. #include <vector>
  7. #include <algorithm>
  8. using namespace std;
  9.   struct dl {
  10.          int time;
  11.          int speed;
  12.          int size;
  13.   };
  14.          bool sort_rows(dl one, dl two) {
  15.                   return one.time < two.time;
  16.          }
  17.   int main() {
  18.                 ifstream in ("downloads.in");
  19.                 ofstream out ("downloads.out");
  20.                 vector <struct dl> files;
  21.                
  22.                 int N;
  23.                 in >> N;
  24.                 int totalT = 0;
  25.                 int totalF = 0;
  26.                 int bandwidth = 0;
  27.                 int Speed, Time;
  28.                 //files[file][0 = speed, 1 = time]
  29.                   for (int i = 0; i < N; i++) {
  30.                                 dl Dl;
  31.                                 in >> Speed >> Time;
  32.                                 Dl.speed = Speed;
  33.                                 Dl.time = Time;
  34.                                 files.push_back(Dl);
  35. //                      in >> files[i][0] >> files[i][1];
  36.                                 totalF++;
  37.                                 bandwidth += Speed;
  38.                   }
  39. //              cout << totalF << endl;
  40.                 sort (files.begin(), files.end(), sort_rows);
  41.                   for (int i = 0; i < totalF; i++) {
  42.                                 totalT += files.at(i).time;
  43.                                   if (i != totalF - 1) {
  44. /*                                       cout << files.at(i).speed << endl;*/
  45. //                                       cout << (files.at(i + 1).speed + files.at(i).speed) << endl;
  46.                                          dl& nextfile = files.at(i + 1);
  47.                                          dl& thisfile = files.at(i);
  48.                                          thisfile.size = (thisfile.time - totalT) * thisfile.speed;
  49.                                          nextfile.size = nextfile.time * nextfile.speed;
  50.                                          int bytesDled = thisfile.time * nextfile.speed;
  51. //                                       cout << nextfile.size << " " << bytesDled << endl;
  52.                                          nextfile.time = (nextfile.size - bytesDled) / (nextfile.speed + thisfile.speed);
  53.                                          nextfile.speed = (nextfile.speed + thisfile.speed);
  54.                                          //                                    
  55. //cout << files.at(i+1).time << endl;
  56.                                   }
  57.                   }
  58.                 out << totalT << endl;
  59.         }