L2-034 口罩发放 (25 分)
题目异常恶心,很多坑。
1.
分发口罩顺序:顺序按照发放顺序确定。
身体状况为 1输出顺序 :顺序按照申请记录中出现的顺序确定,同一个人只需要输出一次。
2 .
身份证和姓名需要特别关注输入数据是否合法。
(本人就是姓名每次都是输入一个字符,改啦一晚上也还是一分,换成string来存姓名直接25)
代码1:
(用啦stable——sort排序还挺香的)
#include <bitsdc++.h>
#include <limits.h>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<double, int> PII;
typedef pair<int, int> pii;
typedef unsigned long long ull;
const ll inf = 0x3f3f3f3f3f3f3f;
map<string, int> ma;
map<string, bool> vis;
struct node {
string s;
string ch;
int is;
int hh, minu, ss;
bool operator<(const node &other) const {
if (hh == other.hh) {
return minu < other.minu;
}
return hh < other.hh;
}
} a[11111];
vector<node> v1, v2;
int main() {
int d, p;
cin >> d >> p;
for (int i = 1; i <= d; i++) {
int s, t;
cin >> t >> s;
for (int ii = 0; ii < t; ii++) {
int flag = 0;
cin >> a[ii].ch >> a[ii].s >> a[ii].is;
scanf("%d:%d", &a[ii].hh, &a[ii].minu);
if (a[ii].s.size() != 18) flag = 1;
for (int j = 0; j < 18; j++) {
if (a[ii].s[j] < '0' || a[ii].s[j] > '9') {
flag = 1;
}
}
if (flag) {
t--;
ii--;
continue;
}
if (ma[a[ii].s] == 0) ma[a[ii].s] = -p - 100;
a[ii].ss = ii;
if (a[ii].is) {
v2.push_back(a[ii]);
}
}
if(t==0)
continue;
stable_sort(a, a + t);
int ii = 0;
int j = 0;
while (ii < t && j < s) {
if (i > ma[a[ii].s] + p) {
v1.push_back(a[ii]);
ma[a[ii].s] = i;
ii++;
j++;
} else
ii++;
}
}
for (int i = 0; i < v1.size(); i++) {
cout << v1[i].ch << " " << v1[i].s << endl;
}
for (int i = 0; i < v2.size(); i++) {
if (vis[v2[i].s]) continue;
vis[v2[i].s] = 1;
cout << v2[i].ch << " " << v2[i].s << endl;
}
return 0;
}
标题代码2:
#include <bits/stdc++.h>
#include <limits.h>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<double, int> PII;
typedef pair<int, int> pii;
typedef unsigned long long ull;
const ll inf = 0x3f3f3f3f3f3f3f;
map<string, int> ma;
map<string, bool> vis;
struct node {
string s;
string ch;
int is;
int hh, minu, ss;
bool operator<(const node &other) const {
if (hh == other.hh) {
if (minu == other.minu) {
return ss < other.ss;
}
return minu < other.minu;
}
return hh < other.hh;
}
} a[11111];
vector<node> v1, v2;
int main() {
int d, p;
cin >> d >> p;
for (int i = 1; i <= d; i++) {
int s, t;
cin >> t >> s;
for (int ii = 0; ii < t; ii++) {
int flag = 0;
cin >> a[ii].ch >> a[ii].s >> a[ii].is;
scanf("%d:%d", &a[ii].hh, &a[ii].minu);
if (a[ii].s.size() != 18) flag = 1;
for (int j = 0; j < 18; j++) {
if (a[ii].s[j] < '0' || a[ii].s[j] > '9') {
flag = 1;
}
}
if (flag) {
t--;
ii--;
continue;
}
if (ma[a[ii].s] == 0) ma[a[ii].s] = -p - 100;
a[ii].ss = ii;
if (a[ii].is) {
v2.push_back(a[ii]);
}
}
if(t==0)
continue;
sort(a, a + t);
int ii = 0;
int j = 0;
while (ii < t && j < s) {
if (i > ma[a[ii].s] + p) {
v1.push_back(a[ii]);
ma[a[ii].s] = i;
ii++;
j++;
} else
ii++;
}
}
for (int i = 0; i < v1.size(); i++) {
cout << v1[i].ch << " " << v1[i].s << endl;
}
for (int i = 0; i < v2.size(); i++) {
if (vis[v2[i].s]) continue;
vis[v2[i].s] = 1;
cout << v2[i].ch << " " << v2[i].s << endl;
}
return 0;
}
代码3:
蓝蓝的代码,帮他找啦个小错误,嫖他个代码来粘上。
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
#define PII pair<int, int>
#define PSS pair<string, string>
#define PSI pair<string, int>
#define pb push_back
#define mem(a, b) memset(a, b, sizeof(a))
#define x first
#define y second
const int N = 3e5 + 10;
using namespace std;
struct node
{
string s;
string id;
int body;
int hh;
int mm;
int pos;
} dp[N];
map<string, int> day;
set<PSS> st;
vector<PSS> peo;
vector<PSS> ans;
vector<node> vp;
bool cmp(node x, node y)
{
if (x.hh != y.hh)
return x.hh < y.hh;
else if (x.mm != y.mm)
return x.mm < y.mm;
else
return x.pos < y.pos;
}
int main()
{
int d, p;
cin >> d >> p;
day.clear();
for (int dd = 1; dd <= d; dd++)
{
int t, s;
cin >> t >> s;
char c;
vp.clear();
for (int i = 1; i <= t; i++)
{
cin >> dp[i].s >> dp[i].id >> dp[i].body >> dp[i].hh >> c >> dp[i].mm;
dp[i].pos = i;
int len = dp[i].id.size();
if (len != 18)
continue;
bool flag = 0;
for (int j = 0; j < 18; j++)
{
if (!isdigit(dp[i].id[j]))
{
flag = 1;
break;
}
}
if (flag)
continue;
if (dp[i].body)
peo.pb(PSS{dp[i].s, dp[i].id});
vp.pb(dp[i]);
}
sort(vp.begin(), vp.end(), cmp);
int len = vp.size();
for (int i = 0; i < len; i++)
{
if (!s)
break;
if (day[vp[i].id] + p < dd || !day[vp[i].id]){
ans.pb(PSS{vp[i].s, vp[i].id});
day[vp[i].id] = dd;
s--;
}
else continue;
}
}
for (int i = 0; i < (int)ans.size(); i++)
{
cout << ans[i].x << " " << ans[i].y << endl;
}
for (int i = 0; i < (int)peo.size(); i++)
{
if (!st.count(peo[i]))
{
cout << peo[i].x << " " << peo[i].y << endl;
st.insert(peo[i]);
}
}
return 0;
}