Open qiaobaaa opened 1 year ago
using namespace std;
struct machines { int id; int time; }machines[MAX_NUM];
unordered_map<int, int>umap; vectorcall;
int index;
struct cmp { bool operator()(int a,int b)const { if (machines[a].time!=machines[b].time) { return machines[a].time > machines[b].time; } else { return machines[a].id > machines[b].id; } } };
set<int, cmp>sset;
void regist(int id,int time) { index++; umap[id] = index; machines[index].id = id; machines[index].time = time; sset.insert(index); }
void init(int N, int mId[], int mTime[]) { umap.clear(); sset.clear(); index = 0; for (int i = 0; i < N; i++) { regist(mId[i], mTime[i]); } return; }
int add(int mId, int mTime) { if (umap.find(mId)==umap.end()) { regist(mId, mTime); } else { sset.erase(umap[mId]); machines[umap[mId]].time = mTime; sset.insert(umap[mId]); } return sset.size(); }
int remove(int K) { for (int i = 0; i < K; i++) { int id = machines[*sset.begin()].id; umap.erase(id);
sset.erase(sset.begin()); } return machines[*sset.begin()].id;
} int binary(int l,int h ,int m) { call.clear(); int low = l; int high = h; int mid; int i = 0; int temp;
int count1=h; for (auto it=sset.begin();it!=sset.end();it++) { call.push_back(machines[*it].time); i++; } //二分法的核心过程了 while (low<=high) { temp = 0; mid = (low + high) >>1; for (int j = 0; j < i; j++) { temp = temp + (mid / call[j]); } if (temp>=m) { count1 = mid; high = mid - 1; } else { low = mid + 1; } } return count1;
} int produce(int M) { int count1 = 0; auto it = sset.rbegin(); count1 = binary(0,M(machines[it].time),M); return count1; }
set vector
include
include
include
define MAX_NUM 25000
using namespace std;
struct machines { int id; int time; }machines[MAX_NUM];
unordered_map<int, int>umap; vectorcall;
int index;
struct cmp { bool operator()(int a,int b)const { if (machines[a].time!=machines[b].time) { return machines[a].time > machines[b].time; } else { return machines[a].id > machines[b].id; } } };
set<int, cmp>sset;
void regist(int id,int time) { index++; umap[id] = index; machines[index].id = id; machines[index].time = time; sset.insert(index); }
void init(int N, int mId[], int mTime[]) { umap.clear(); sset.clear(); index = 0; for (int i = 0; i < N; i++) { regist(mId[i], mTime[i]); } return; }
int add(int mId, int mTime) { if (umap.find(mId)==umap.end()) { regist(mId, mTime); } else { sset.erase(umap[mId]); machines[umap[mId]].time = mTime; sset.insert(umap[mId]); } return sset.size(); }
int remove(int K) { for (int i = 0; i < K; i++) { int id = machines[*sset.begin()].id; umap.erase(id);
} int binary(int l,int h ,int m) { call.clear(); int low = l; int high = h; int mid; int i = 0; int temp;
} int produce(int M) { int count1 = 0; auto it = sset.rbegin(); count1 = binary(0,M(machines[it].time),M); return count1; }