有一种情况没处理好,后面再想想怎么弄
int main()
{
unordered_map<int, priority_queue<int,vector<int>,greater<int>>>m;
int m1;
cin >> m1;
int n;
int count = 0;
vector<int>hehe(101, 0);
while (m1--)
{
cin >> n;
int tmp1 = n;
while (n <= 4)
{
if (!m[n].empty())
{
int tmp = m[n].top();
m[n].pop(); //删除当前保留的位置
m[n - tmp1].push(tmp + tmp1);
int tmp2 = tmp1;
while (tmp2--) //输出票的位置
{
cout << tmp << " ";
hehe[tmp] = 1; //保存票的位置
tmp++;
}
break;
}
n++;
}
if (n > 4) //找不到空位置
{
if (count < 20) //如果还有空余的整排
{
m[5 - tmp1].push(5 * count + tmp1 + 1);
int tmp2 = 1;
while (tmp1--)
{
cout << 5 * count + tmp2 << ' ';
hehe[5 * count + tmp2] = 1;
tmp2++;
}
count++;
}
else //没有空余的排
{
for (int i = 1; i <= 100&&tmp1>0; ++i,tmp1--)
{
if (hehe[i] == 0)
{
hehe[i] = 1;
cout << i << " ";
}
}
}
}
cout << endl;
}
}