Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Producing Machines #13

Open
qiaobaaa opened this issue Jun 5, 2023 · 1 comment
Open

Producing Machines #13

qiaobaaa opened this issue Jun 5, 2023 · 1 comment

Comments

@qiaobaaa
Copy link
Owner

qiaobaaa commented Jun 5, 2023

#include<unordered_map>
#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);

    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;
}

@qiaobaaa
Copy link
Owner Author

qiaobaaa commented Jun 5, 2023

set vector

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant