Open qiaobaaa opened 1 year ago
using namespace std;
int C; int N; int id; struct child{ int pos; pair<int,int> sc[10];
}student[10005];
struct sch{ int x,y;
}school[10]; set<pair<int,int>>S[10], W[10]; unordered_map<int,int>sid;
void init(int C, int N, int mX[], int mY[]){ ::C=C; ::N=N; for(int i=0;i<N;i++){ school[i] = {mX[i],mY[i]}; S[i].clear(); W[i].clear();
}
sid.clear();
id =0;
} void update(int p, int mid){ int val = student[p].sc[N-1].first; for(int k=0;k<N;k++){ pair<int,int> x = student[p].sc[k]; if(S[x.second].size()<C){ student[p].pos = x.second; S[x.second].insert({-val,mid});
return;
}
else{
pair<int,int> cur = *S[x.second].rbegin();
if(-cur.first<val || -cur.first==val && mid <cur.second){
S[x.second].erase(cur);
S[x.second].insert({-val,mid});
student[p].pos = x.second;
update(sid[cur.second],cur.second);
return;
}
else{
W[x.second].insert({-val,mid});
}
}
}
}
void rm_update(int p){ if(!W[p].empty()){ pair<int,int> cur = *W[p].begin(); W[p].erase(cur); int cid = sid[cur.second]; int prev = student[cid].pos; S[prev].erase(cur); S[p].insert(cur); student[cid].pos = p; rm_update(prev);
}
}
int add(int mStudent, int mX, int mY){ sid[mStudent]= ++id; student[id] = {}; for(int i=0;i<N;i++){ student[id].sc[i] = {abs(mX-school[i].x)+abs(mY-school[i].y),i}; } sort(student[id].sc,student[id].sc+N); update(id,mStudent); return student[id].pos; }
int remove(int mStudent){ int rid = sid[mStudent], val = student[rid].sc[N - 1].first, p = student[rid].pos; S[p].erase({ -val, mStudent }); for (int i = 0; i < N; i++) W[i].erase({ -val, mStudent }); rm_update(p); return p; } int status(int mSchool){ return S[mSchool].size(); }
set algo
include
include
include
include
include
using namespace std;
int c, n; struct MyStruct { vectorse;
int id;
int school;
int max_distance;
unordered_map<int, int>record;
}s[7501];
struct cmp { bool operator()(int a, int b)const { if (s[a].max_distance != s[b].max_distance) { return s[a].max_distance > s[b].max_distance; } else { return s[a].id < s[b].id; } } };
set<int, cmp>school[10]; set<int, cmp>all; unordered_map<int, int>stu; int sum; pair<int, int>sss[10];
void init(int C, int N, int mX[], int mY[]) { c = C; n = N; sum = 0; stu.clear(); all.clear(); for (register int i = 0; i < N; i++) { school[i].clear(); sss[i] = make_pair(mX[i], mY[i]); }
}
void arrange(int num) { for (auto i : s[num].se) { //按距离最近的开始遍历选择,如果还有空位置就可以直接加入 if (school[i].size() < c) { s[num].school = i; school[i].emplace(num); all.emplace(num); return; } else { //人已经满了会产生3种情况; // 1.跟最后的一名的距离都小于,把原来学校最小优先级的学生都挤不走,只能到下一轮 //2.跟最后的一名的距离相等,但是id却大于,到下一轮 //3. 跟最后的一名的距离相等,但是id却小于,把最后一名挤走 //4.比最后一名距离大,直接把最后一名挤走 int n = *school[i].rbegin(); if (s[n].max_distance == s[num].max_distance) { //3 if (s[n].id > s[num].id) { s[num].school = i; school[i].emplace(num); all.emplace(num); all.erase(n); school[i].erase(n); //按照一层一层往下推,直到全安排好 arrange(n); return; } } else if (s[n].max_distance < s[num].max_distance) { //4 s[num].school = i; school[i].emplace(num); all.emplace(num); all.erase(n); school[i].erase(n); //按照一层一层往下推,直到全安排好 arrange(n); return; } } } }
int add(int mStudent, int mX, int mY) { stu[mStudent] = sum; vector<pair<int, int>>tem; for (register int i = 0; i < n; i++) { int x = sss[i].first - mX < 0 ? mX - sss[i].first : sss[i].first - mX; int y = sss[i].second - mY < 0 ? mY - sss[i].second : sss[i].second - mY; tem.push_back(make_pair(x + y, i)); } sort(tem.begin(), tem.end()); //该同学的最远距离 s[sum].max_distance = tem.rbegin()->first; s[sum].id = mStudent; //把该同学依次最近的学校给输入进来 int g = 1; for (auto i : tem) { s[sum].se.push_back(i.second); s[sum].record[i.second] = g; g++; }
}
void brrange(int result, int pos) { //不需要移动 if (school[s[result].school].size() < c) { //把原来的删除 school[s[result].school].erase(result); //添加到新的位置
}
int remove(int mStudent) {
}
int status(int mSchool) { return school[mSchool].size(); }