Advertisement
rafid_shad

Telephony system

Aug 10th, 2021
697
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.78 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define read()              freopen("in.txt", "r", stdin)
  5. #define write()             freopen("out.txt", "w", stdout)
  6.  
  7. #define loop(i, n)          for(int i = 0; i < n; i++)
  8. #define loopt(i, n)         for(int i = 1; i <= n; i++)
  9.  
  10. struct nxt
  11. {
  12.     int x, y, z, l;
  13.     nxt(){}
  14.     nxt(int xx, int yy, int len, int zz){
  15.         x = xx;
  16.         y = yy;
  17.         z = zz;
  18.         l = len;
  19.     }
  20. };
  21. struct info{
  22.     int x, y, z;
  23.     info(){}
  24.     info(int xx, int yy, int zz){
  25.         x = xx;
  26.         y = yy;
  27.         z = zz;
  28.     }
  29.     bool operator < (const info &b) const{
  30.         return z > b.z;
  31.     }
  32. };
  33.  
  34. nxt a[50];
  35. int line[50];
  36. int lk, clk, cnt, avl,ln;
  37. int busy, blocked, completed, processed;
  38. int progressbar[50][3];
  39.  
  40. int idx = 1;
  41. int total = 0;
  42. int lol = 0;
  43.  
  44. void add(int u, int v, int x){
  45.     loop(i, lk){
  46.         if(progressbar[i][0] == 0){
  47.             progressbar[i][0] = u;
  48.             progressbar[i][1] = v;
  49.             progressbar[i][2] = x;
  50.             break;
  51.         }
  52.     }
  53. }
  54.  
  55. void remove(int u, int v, int x){
  56.     loop(i, lk){
  57.         if(progressbar[i][0] == u){
  58.             progressbar[i][0] = 0;
  59.             progressbar[i][1] = 0;
  60.             progressbar[i][2] = 0;
  61.             break;
  62.         }
  63.     }
  64. }
  65.  
  66. void print(int ch){
  67.     cout << endl << endl;
  68.     cout << "Step " << ++lol << ":"<< endl;
  69.     cout << "-----------------------------------------------------------------------" << endl;
  70.     cout << "[Next Call]" << endl;
  71.     if(ch != 3){
  72.          cout << "From     To        lenght      A.time" << endl;
  73.          cout << a[idx].x << "         " << a[idx].y << "         " << a[idx].l << "          "<< a[idx].z << "( " << a[idx].z / 60 << ": " << a[idx].z%60 << ")"<< endl<< endl;
  74.     }
  75.     else{
  76.         cout << "From     To        lenght      A.time" << endl;
  77.         loopt(i, avl){
  78.              cout << a[i].x << "         " << a[i].y << "         " << a[i].l << "          "<< a[i].z  << "( " << a[i].z / 60 << ": " << a[i].z%60 << ")" << endl;
  79.         }
  80.         cout << endl;
  81.     }
  82.     cout << "[Lines]" << endl;
  83.     loopt(i, ln) cout << i << ": "<< line[i] <<endl;;
  84.     cout << endl ;
  85.     cout << "clock -> " << clk  << "( " << clk / 60 << ": " << clk%60 << ")" << endl;
  86.     cout << "Max Link -> " << lk << endl;
  87.     cout << "Used Link -> " << total/2 << endl;
  88.     if(ch == -1) cout << "Verdict -> 'BLOCKED'" << endl << endl;
  89.     else if(ch == 0) cout << "Verdict -> 'BUSY'" << endl << endl;
  90.     else if(ch == 1) cout << "Verdict -> 'COMPLETED'" << endl << endl;
  91.     else if(ch == 2) cout << "Verdict -> 'ADDED'" << endl << endl;
  92.     else if(ch == 3) cout << "Verdict -> 'GIVEN in QUESTION'" << endl << endl;
  93.     cout << "[Call in Progress]" << endl;
  94.     cout << "From      To         End" << endl;
  95.     loop(i, lk){
  96.         if(progressbar[i][0]){
  97.             cout << progressbar[i][0] << "         " << progressbar[i][1] << "          " << progressbar[i][2]
  98.             << "( " << progressbar[i][2] / 60 << ": " << progressbar[i][2]%60 << ")"  << endl;
  99.         }
  100.     }
  101.     cout << endl << endl;
  102.     cout << "[Call Counter]" << endl;
  103.     cout << "processed        completed        blocked             busy " << endl;
  104.     cout << processed << "               " << completed<<"                 " << blocked << "                 " << busy << endl << endl;
  105.     cout << "===========================================================================" << endl;
  106.     cout << endl <<endl;
  107. }
  108.  
  109. int main(){
  110.  
  111.     #ifndef ONLINE_JUDGE
  112.     read();
  113.     write();
  114.     #endif // ONLINE_JUDGE
  115.     //fastIO;
  116.  
  117.    // cout << "Enter Link " << endl;
  118.     cin >> lk;
  119.  
  120.    // cout << "Enter line " << endl;
  121.     cin >> ln;
  122.  
  123.    // cout << "Enter clock time " << endl;
  124.     cin >> clk;
  125.  
  126.    // cout << "Enter call counter (processed, compledted, bloked, busy)" << endl;
  127.     cin >> processed >> completed >> blocked >> busy;
  128.  
  129.    // cout << "Enter how many call are in arrival " << endl;
  130.     cin >> avl;
  131.  
  132.     loopt(i, avl){
  133.         cin >> a[i].x >> a[i].y >> a[i].l >> a[i].z;
  134.     }
  135.  
  136.    // cout << "Enter how many calls are  in progress " << endl;
  137.     cin >> cnt;
  138.  
  139.     priority_queue <info> q;
  140.  
  141.     loop(i, cnt){
  142.         int u, v, x;
  143.         cin >> u >> v >> x;
  144.         line[u] = 1;
  145.         line[v] = 1;
  146.         q.push(info(u, v, x));
  147.         total += 2;
  148.         add(u, v, x);
  149.     }
  150.     print(3);
  151.     while(!q.empty() or idx <= avl){
  152.         int val = 1e9;
  153.         int mnn = 1e9;
  154.         if(!q.empty()){
  155.             info cur = q.top();
  156.             val = cur.z;
  157.         }
  158.         if(idx <= avl )mnn = a[idx].z;
  159.         int mn = min(mnn, val);
  160.         if(mn == val){
  161.             if(!q.empty() ){
  162.                 info cur = q.top();
  163.                 if(cur.z != mn) break;
  164.                 line[cur.x] = 0;
  165.                 line[cur.y] = 0;
  166.                 total -= 2;
  167.                 remove(cur.x, cur.y, mn);
  168.                 q.pop();
  169.                 completed++;
  170.                 processed++;
  171.                 clk = mn;
  172.             }
  173.             print(1);
  174.         }
  175.         else if(mn == mnn){
  176.             if(total/2 == lk){
  177.                 blocked++;
  178.                 processed++;
  179.                 clk = mn;
  180.                 idx++;
  181.                 print(-1);
  182.                 continue;
  183.             }
  184.             if(line[a[idx].x] or line[a[idx].y]){
  185.                 busy++;
  186.                 processed++;
  187.                 clk = mn;
  188.                 idx++;
  189.                 print(0);
  190.                 continue;
  191.             }
  192.             q.push (info(a[idx].x, a[idx].y, mn + a[idx].l));
  193.             add( a[idx].x, a[idx].y, mn + a[idx].l );
  194.             line[a[idx].x] = 1;
  195.             line[a[idx].y] = 1;
  196.             clk = mn;
  197.             total += 2;
  198.             idx++;
  199.             print(2);
  200.         }
  201.     }
  202. }
  203.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement