标签:div turn space 忽略 图形 系统 erase data ret
1 #include<iostream> 2 #include<vector> 3 using namespace std; 4 5 struct node 6 { 7 int x1,y1,x2,y2; 8 int num; 9 node(int a=0,int b=0,int c=0,int d=0,int e=0):x1(a),y1(b),x2(c),y2(d),num(e){ // 必须 得赋 初 值 ! ! ?? 10 } 11 }; 12 vector<node>windows; 13 14 int find(int x,int y,node t) 15 { 16 if (x>=t.x1 && x<=t.x2 && y>=t.y1 && y<=t.y2)return 1; 17 else return 0; 18 } 19 20 void search(int x,int y) 21 { 22 for (int i=0;i<windows.size();i++) 23 { 24 if(find(x,y,windows[i])) 25 { 26 cout<<windows[i].num<<endl; 27 // vector<node>::iterator it= windows.begin(); // 多余!!! 28 node tmp = windows[i]; /// ???? 29 windows.erase(windows.begin()+i); 30 windows.insert(windows.begin(),tmp); 31 return ; 32 } 33 } 34 cout<<"IGNORED"<<endl; 35 36 } 37 38 int main() 39 { 40 41 int n,m; 42 cin>>n>>m; 43 windows.resize(n); 44 45 for (int i =0;i<n;i++) 46 { 47 int x1,y1,x2,y2; 48 cin>>x1>>y1>>x2>>y2; 49 windows[n-i-1]= node(x1,y1,x2,y2,i+1); // window[i] = node() ! ! ! ! ! 50 51 } 52 53 for (int i = 0;i<m;i++) 54 { 55 int x,y; 56 cin>>x>>y; 57 58 search(x,y); 59 60 } 61 62 63 return 0; 64 65 }
(2) 模拟
1 #include<iostream> 2 #include<vector> 3 using namespace std; 4 5 struct node 6 { 7 int x1,x2,y1,y2; 8 int priority; 9 int num; 10 11 }; 12 13 int main() 14 { 15 int n,m; 16 cin>>n>>m; 17 18 struct node a[n]; 19 20 for (int i=0;i<n;i++) 21 { 22 int x1,y1,x2,y2; 23 cin>>x1>>y1>>x2>>y2; // 结 构体的初始化 ,以及分配内存 24 a[i].x1 = x1; 25 a[i].y1 = y1; 26 a[i].x2 = x2; 27 a[i].y2 = y2; 28 a[i].priority = i; 29 a[i].num =i+1; 30 } 31 32 vector<int>v; 33 34 for (int i = 0;i<m;i++) 35 { 36 int x,y; 37 cin>>x>>y; 38 39 for (int j = 0;j<n;j++) // 寻找属于哪个窗口 , 如果没有 40 { 41 int x1,y1,x2,y2; 42 x1 = a[j].x1; y1 = a[j].y1; x2 = a[j].x2; y2 = a[j].y2; 43 if (x >= x1 && x <=x2 && y >= y1 && y <= y2)v.push_back(j); // v 只保存下标! 44 } 45 46 47 48 if (v.size() == 0) 49 { 50 cout<<"IGNORED"<<endl; 51 continue; // 此次循环结束 52 } 53 54 int p = a[v[0]].priority; 55 int chop = a[v[0]].num; 56 int tmp = 0; 57 58 for (int j = 1;j<v.size();j++) // 同 时符合, 比较窗口间的优先级 59 { 60 if (a[v[j]].priority > p) 61 { 62 p = a[v[j]].priority; 63 chop = a[v[j]].num; //选择窗口编号 64 tmp = j; 65 } 66 } 67 68 a[v[tmp]].priority = 121; // 将挑选出来的优先级设为最大; 69 70 71 cout<< chop<<endl; // 输出结果 72 v.clear(); // 清空 v ; 73 74 // 调整优先级 75 76 for (int j = 0;j<n;j++) 77 { 78 a[j].priority = a[j].priority -1; 79 } 80 81 } 82 83 84 return 0; 85 }
(3) 错误模拟,, 对 vector 操作,没有影响到 原数组
1 #include<iostream> 2 #include<vector> 3 using namespace std; 4 5 struct node 6 { 7 int x1,x2,y1,y2; 8 int priority; 9 int num; 10 11 }; 12 13 int main() 14 { 15 int n,m; 16 cin>>n>>m; 17 18 struct node a[n]; 19 20 for (int i=0;i<n;i++) 21 { 22 int x1,y1,x2,y2; 23 cin>>x1>>y1>>x2>>y2; // 结 构体的初始化 ,以及分配内存 24 a[i].x1 = x1; 25 a[i].y1 = y1; 26 a[i].x2 = x2; 27 a[i].y2 = y2; 28 a[i].priority = i; 29 a[i].num =i+1; 30 } 31 32 vector<node>v; 33 // v.clear(); 34 // v.push_back(1); 35 // cout<<v.size(); 36 // 37 for (int i = 0;i<m;i++) 38 { 39 int x,y; 40 cin>>x>>y; 41 42 for (int j = 0;j<n;j++) // 寻找属于哪个窗口 , 如果没有 43 { 44 int x1,y1,x2,y2; 45 x1 = a[j].x1; y1 = a[j].y1; x2 = a[j].x2; y2 = a[j].y2; 46 if (x >= x1 && x <=x2 && y >= y1 && y <= y2)v.push_back(a[j]); // 同时符合 47 } 48 49 cout<<"v-->> size: "<< v.size()<<endl; 50 51 for (int j = 0;j<n;j++)cout<<j<<" priority: -->. "<<a[j].priority<<" "; 52 53 if (v.size() == 0) 54 { 55 cout<<"IGNORED"; 56 continue; // 此次循环结束 57 } 58 59 int p = v[0].priority; 60 int chop = v[0].num; 61 int tmp = 0; 62 63 for (int j = 1;j<v.size();j++) // 同 时符合, 比较窗口间的优先级 64 { 65 if (v[j].priority > p) 66 { 67 p = v[j].priority; 68 chop = v[j].num; //选择窗口编号 69 tmp = j; 70 } 71 } 72 cout<< "tmp ->> "<<tmp <<endl; 73 cout<<"v [tmp] "<<v[tmp].priority<<endl; 74 75 v[tmp].priority = 11; // 将挑选出来的优先级设为最大; // 对 v操作 不影响 a !! !!! 出现错误 76 77 cout<<" v[tmp]_change "<< v[tmp].priority<<endl; 78 79 cout<<" x1 ,y1,x2,y2 "<<v[tmp].x1<<" "<<v[tmp].y1<< " "<<v[tmp].x2<<" "<<v[tmp].y2<< " --"<<v[tmp].priority <<endl; 80 81 82 cout<< chop <<endl; // 输出结果 83 // v.clear(); // 清空 v ; 84 85 // 调整优先级 86 87 for (int j = 0;j<n;j++) 88 { 89 cout<< a[j].priority<<" "; 90 a[j].priority = a[j].priority -1; 91 } 92 93 94 95 } 96 97 98 return 0; 99 }
标签:div turn space 忽略 图形 系统 erase data ret
原文地址:https://www.cnblogs.com/wuxiaotianC/p/9503993.html