Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define read() freopen("in.txt", "r", stdin)
- #define write() freopen("out.txt", "w", stdout)
- #define loop(i, n) for(int i = 0; i < n; i++)
- #define loopt(i, n) for(int i = 1; i <= n; i++)
- struct nxt
- {
- int x, y, z, l;
- nxt(){}
- nxt(int xx, int yy, int len, int zz){
- x = xx;
- y = yy;
- z = zz;
- l = len;
- }
- };
- struct info{
- int x, y, z;
- info(){}
- info(int xx, int yy, int zz){
- x = xx;
- y = yy;
- z = zz;
- }
- bool operator < (const info &b) const{
- return z > b.z;
- }
- };
- nxt a[50];
- int line[50];
- int lk, clk, cnt, avl,ln;
- int busy, blocked, completed, processed;
- int progressbar[50][3];
- int idx = 1;
- int total = 0;
- int lol = 0;
- void add(int u, int v, int x){
- loop(i, lk){
- if(progressbar[i][0] == 0){
- progressbar[i][0] = u;
- progressbar[i][1] = v;
- progressbar[i][2] = x;
- break;
- }
- }
- }
- void remove(int u, int v, int x){
- loop(i, lk){
- if(progressbar[i][0] == u){
- progressbar[i][0] = 0;
- progressbar[i][1] = 0;
- progressbar[i][2] = 0;
- break;
- }
- }
- }
- void print(int ch){
- cout << endl << endl;
- cout << "Step " << ++lol << ":"<< endl;
- cout << "-----------------------------------------------------------------------" << endl;
- cout << "[Next Call]" << endl;
- if(ch != 3){
- cout << "From To lenght A.time" << endl;
- cout << a[idx].x << " " << a[idx].y << " " << a[idx].l << " "<< a[idx].z << "( " << a[idx].z / 60 << ": " << a[idx].z%60 << ")"<< endl<< endl;
- }
- else{
- cout << "From To lenght A.time" << endl;
- loopt(i, avl){
- cout << a[i].x << " " << a[i].y << " " << a[i].l << " "<< a[i].z << "( " << a[i].z / 60 << ": " << a[i].z%60 << ")" << endl;
- }
- cout << endl;
- }
- cout << "[Lines]" << endl;
- loopt(i, ln) cout << i << ": "<< line[i] <<endl;;
- cout << endl ;
- cout << "clock -> " << clk << "( " << clk / 60 << ": " << clk%60 << ")" << endl;
- cout << "Max Link -> " << lk << endl;
- cout << "Used Link -> " << total/2 << endl;
- if(ch == -1) cout << "Verdict -> 'BLOCKED'" << endl << endl;
- else if(ch == 0) cout << "Verdict -> 'BUSY'" << endl << endl;
- else if(ch == 1) cout << "Verdict -> 'COMPLETED'" << endl << endl;
- else if(ch == 2) cout << "Verdict -> 'ADDED'" << endl << endl;
- else if(ch == 3) cout << "Verdict -> 'GIVEN in QUESTION'" << endl << endl;
- cout << "[Call in Progress]" << endl;
- cout << "From To End" << endl;
- loop(i, lk){
- if(progressbar[i][0]){
- cout << progressbar[i][0] << " " << progressbar[i][1] << " " << progressbar[i][2]
- << "( " << progressbar[i][2] / 60 << ": " << progressbar[i][2]%60 << ")" << endl;
- }
- }
- cout << endl << endl;
- cout << "[Call Counter]" << endl;
- cout << "processed completed blocked busy " << endl;
- cout << processed << " " << completed<<" " << blocked << " " << busy << endl << endl;
- cout << "===========================================================================" << endl;
- cout << endl <<endl;
- }
- int main(){
- #ifndef ONLINE_JUDGE
- read();
- write();
- #endif // ONLINE_JUDGE
- //fastIO;
- // cout << "Enter Link " << endl;
- cin >> lk;
- // cout << "Enter line " << endl;
- cin >> ln;
- // cout << "Enter clock time " << endl;
- cin >> clk;
- // cout << "Enter call counter (processed, compledted, bloked, busy)" << endl;
- cin >> processed >> completed >> blocked >> busy;
- // cout << "Enter how many call are in arrival " << endl;
- cin >> avl;
- loopt(i, avl){
- cin >> a[i].x >> a[i].y >> a[i].l >> a[i].z;
- }
- // cout << "Enter how many calls are in progress " << endl;
- cin >> cnt;
- priority_queue <info> q;
- loop(i, cnt){
- int u, v, x;
- cin >> u >> v >> x;
- line[u] = 1;
- line[v] = 1;
- q.push(info(u, v, x));
- total += 2;
- add(u, v, x);
- }
- print(3);
- while(!q.empty() or idx <= avl){
- int val = 1e9;
- int mnn = 1e9;
- if(!q.empty()){
- info cur = q.top();
- val = cur.z;
- }
- if(idx <= avl )mnn = a[idx].z;
- int mn = min(mnn, val);
- if(mn == val){
- if(!q.empty() ){
- info cur = q.top();
- if(cur.z != mn) break;
- line[cur.x] = 0;
- line[cur.y] = 0;
- total -= 2;
- remove(cur.x, cur.y, mn);
- q.pop();
- completed++;
- processed++;
- clk = mn;
- }
- print(1);
- }
- else if(mn == mnn){
- if(total/2 == lk){
- blocked++;
- processed++;
- clk = mn;
- idx++;
- print(-1);
- continue;
- }
- if(line[a[idx].x] or line[a[idx].y]){
- busy++;
- processed++;
- clk = mn;
- idx++;
- print(0);
- continue;
- }
- q.push (info(a[idx].x, a[idx].y, mn + a[idx].l));
- add( a[idx].x, a[idx].y, mn + a[idx].l );
- line[a[idx].x] = 1;
- line[a[idx].y] = 1;
- clk = mn;
- total += 2;
- idx++;
- print(2);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement