Untitled
unknown
plain_text
a year ago
3.1 kB
8
Indexable
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <unordered_map>
using namespace std;
#define MAX_N 10
#define MAX_ORDER 20000
void makeCookies(int mID);
struct Order
{
int stt;
int shape, start_day, left_day;
} order[20001];
struct Cutter
{
int N;
vector<int> shape_list;
int shape[1001];
} cutter[101];
struct compare
{
bool operator() (int a,int b)
{
if(order[a].left_day==order[b].left_day)
{
if(order[a].start_day==order[b].start_day) return order[a].stt<order[b].stt;
return order[a].start_day<order[b].start_day;
}
return order[a].left_day<order[b].left_day;
}
};
int cur_day,stt_order,N_cutter;
set<int,compare> count_shape[1001];
set<int,compare> list_order;
void init(void)
{
cur_day=0;
stt_order=0;
N_cutter=0;
list_order.clear();
for(int i=0;i<1001;i++)
{
count_shape[i].clear();
}
for(int i=0;i<101;i++)
{
cutter[i].shape_list.clear();
for(int j=0;j<1001;j++) cutter[i].shape[j]=0;
}
}
void addCookieCutter(int mID, int N, int mShapeList[])
{
N_cutter++;
cutter[mID].N=N;
for(int i=0;i<N;i++)
{
cutter[mID].shape_list.push_back(mShapeList[i]);
cutter[mID].shape[mShapeList[i]]=1;
}
}
void orderCookie(int mShape, int daysLeft)
{
stt_order++;
order[stt_order].stt=stt_order;
order[stt_order].start_day=cur_day;
order[stt_order].shape=mShape;
order[stt_order].left_day=cur_day+daysLeft;
list_order.insert(stt_order);
count_shape[mShape].insert(stt_order);
}
int checkRemain(int mShape)
{
return count_shape[mShape].size();
}
void newDay(void)
{
cur_day++;
while(!list_order.empty())
{
int it=*list_order.begin();
if(order[it].left_day==cur_day)
{
int shape=order[it].shape;
int temp_count=0;
int temp_cutter=0;
for(int i=1;i<=N_cutter;i++)
{
int temp=0;
if(cutter[i].shape[shape]==1)
{
for(int j=0;j<cutter[i].N;j++)
{
if(count_shape[cutter[i].shape_list[j]].size()>0) temp++;
}
if(temp>temp_count)
{
temp_count=temp;
temp_cutter=i;
}
}
}
makeCookies(temp_cutter);
for(int i=0;i<cutter[temp_cutter].N;i++)
{
if(!count_shape[cutter[temp_cutter].shape_list[i]].empty())
{
list_order.erase(*count_shape[cutter[temp_cutter].shape_list[i]].begin());
count_shape[cutter[temp_cutter].shape_list[i]].erase(count_shape[cutter[temp_cutter].shape_list[i]].begin());
}
}
}
else break;
}
}Editor is loading...
Leave a Comment