L2-034 口罩发放 (25 分)——坑点分析

题目传送门

坑点分析

思路大家应该都明确,说说坑点

  1. s可能为0, 口罩没有名额
  2. 同一天,一个人可能申请多次!!
  3. 输出身体状况为 1 的人是,只要这个人的ID合法且为1,就要存下来输出,顺序按照输入的顺序
  4. 检查ID是否合法,不仅要判断是否为18位,还要判断每一位是否都是数字

AC代码

#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x; i<=y; ++i)
#define per(i,x,y) for(int i=x; i>=y; --i)
#define pushk push_back
#define popk pop_back
#define mem(a,b) memset(a,b,sizeof a)
#define PII pair<int,int>
#define ll long long
#define lp p<<1
#define rp p<<1|1
#define INF 0x3f3f3f3f
using namespace std;
const int N = 1e4+9;
struct People{
	string name,ID;
	int hy;
	string time;
	int idx;
	bool operator<(const People & t) const{
		if(time!=t.time) return time<t.time;
		else return idx<t.idx;
	}
};
struct PP{
	string name,ID;
	int idx;
	bool operator<(const PP & t) const{
		return idx<t.idx;
	}
};
unordered_map<string,int> mp,vis,cc,hh;
bool check(string id){
	if(id.size()!=18) return false;
	rep(i,0,17){
		if(id[i]<'0' || id[i]>'9') return 0; 
	} 
	return 1;
}
int main() {
	
	ios::sync_with_stdio(false),cin.tie(0);
	int d,p;
	cin>>d>>p;
	set<PP> se;
	int cnt=0;
	rep(i,1,d){
		int t,s;
		cin>>t>>s;
		vector<People> ve;
		rep(j,1,t){
			string name,ID,time;
			int hy;
			cin>>name>>ID>>hy>>time;
			if(!check(ID)) continue;
			cnt++;
			if(hy==1 && vis[ID]==0) se.insert({name,ID,cnt}),vis[ID]++;
			if(mp[ID] && i-mp[ID]<=p ) continue;
			ve.pushk({name,ID,hy,time,j});
		
		} 
		if(s==0) continue;
		sort(ve.begin(), ve.end());
		for(auto &it : ve){
			if(mp[it.ID]==i) continue;
			cout<<it.name<<" "<<it.ID<<'\n';
			mp[it.ID]=i;
			s--;
			if(s<=0) break;
		}
	} 
	for(auto &it : se){
		cout<<it.name<<" "<<it.ID<<'\n';
	}
	return 0;
}


一点废话

室友打呼噜睡不着,真的要哭了,起来做一道恶心的题,恶心恶心自己,累了睡大觉

  • 5
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值