【蓝桥杯一键通关班】剩余题目
作者:互联网
第三章 唯一剩下的 —— 外卖店优先级
//结构体排序
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
const int N = 1e5 + 10;
int flag[N]; //记录第id个商店的优先级
int tap[N];
int output[N];
struct node
{
int time;
int id;
}nodes[N];
bool cmp(node a, node b)
{
if (a.id != b.id)return a.id < b.id;
if (a.time != b.time)return a.time < b.time;
return a.time < b.time;
}
int main()
{
int n, m, t;
cin >> n >> m >> t;
//n个外卖店 m个订单 t时间内
for (int i = 0; i < m; i++)
cin >> nodes[i].time >> nodes[i].id;
sort(nodes, nodes + m, cmp);
// for (int i = 0; i < m; i++)cout << nodes[i].time << ' ' << nodes[i].id << endl;
int cnt = 0;
//计算每一个商店有几个订单
for (int i = 0; i < m; i++)
{
if (nodes[i].id == nodes[i + 1].id)tap[cnt]++;
else tap[cnt]++, cnt++;
}
int k = 0; //指向有效订单从0 指向m
for (int i = 0, k = 0; i < n; i++) //讨论每一个商店
{
//每个商店有tap[i]个订单
for (int j = nodes[k].time, tmp = 0; j <= t; j++) //一共遍历的时间
{
// cout << flag[i] << ' ' << j << endl;
if (flag[i] > 5)output[i] = 1;
if (flag[i] <= 3)output[i] = 0;
int yy = 0;
while((j == nodes[k].time) && (tmp < tap[i])) flag[i] += 2, k++,tmp++,yy = 1;
if (flag[i] > 5)output[i] = 1;
if (flag[i] <= 3)output[i] = 0;
if (yy == 1)continue;
if (tmp >= tap[i]) flag[i] -= 1;
else if (j != nodes[k].time) flag[i] -= 1;
if (flag[i] <= 0) flag[i] = 0;
if (flag[i] > 5)output[i] = 1;
if (flag[i] <= 3)output[i] = 0;
}
}
int ans = 0;
for (int i = 0; i < n; i++)
{
cout << flag[i] << endl;
if ( flag[i] >= 4 && output[i] ==1)ans++; //上过>5 并且现在不能小于
}
cout << endl << ans << endl;
return 0;
}
我一开始的做法:按照他的要求,踢皮球一般看一个要求写一些。没有全局观,导致TEL。
标签:int,一键,蓝桥,flag,time,output,nodes,id,通关 来源: https://www.cnblogs.com/thehomeof99/p/15940610.html