Problem Link
Problem Type : Data Structure.
Difficulty Level : Moderate
Author : Imdad
Briefly problem statement
initialization sequence 1 to n, each operation will delete the specified interval, and returns the position of the point is not deleted interval at both ends of the closest, If you do not return an asterisk.
Here, is the C++ implementation of this problem.
Problem Type : Data Structure.
Difficulty Level : Moderate
Author : Imdad
Briefly problem statement
initialization sequence 1 to n, each operation will delete the specified interval, and returns the position of the point is not deleted interval at both ends of the closest, If you do not return an asterisk.
Here, is the C++ implementation of this problem.
#include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <vector> #include <set> #include <map> #include <string> #include <list> #include <stack> #include <queue> #include <algorithm> using namespace std; #define sz 100005 typedef struct{ int left,right; }data; data node[sz]; int main(){ int s,b,i,j,k,l,r; //freopen("i.txt", "r", stdin); while(scanf("%d %d",&s,&b) && !(!s && !b)){ for(i = 1; i <= s; i++){ node[i].left = i-1; node[i].right = i+1; } node[s].right = 0; for(i = 0; i < b; i++){ scanf("%d %d",&l,&r); if(node[l].left) printf("%d ",node[l].left); else printf("* "); if(node[r].right) printf("%d\n",node[r].right); else printf("*\n"); node[node[l].left].right = node[r].right; node[node[r].right].left = node[l].left; } printf("-\n"); } return 0; }
No comments:
Post a Comment