首页 > 其他分享 >CSP202209_3

CSP202209_3

时间:2022-10-04 12:12:53浏览次数:40  
标签:风险 ch int CSP202209 用户 ans now

CSP202209_3

目录

题目

防疫大数据

思路

大模拟。

大致题意就是针对当前天,给出以当天开始持续七天的风险地区。同时给出一定数量的用户信息,包括其到达的地区及时间,询问有那些用户有风险。

有风险:

  1. 从其到达的时间到当前时间,其所在区域一直为风险地区。
  2. 只考虑近七天的用户行动(忘记的话只有40pts)

注意点:

  1. 因为当天所给的用户信息不会覆盖所有用户,因而可能存在某些用户信息未更细但依然有风险(其实看看样例就懂),因此在考虑当天时首先要维护前一天的风险用户。
  2. map 在用下标访问时如果是未被声明key,会自动创建该key及对应的val(老是忘记qwq,总之结合情况用迭代器或 count 就好了)

map 维护所有地区在对应时间的风险情况,vector 维护风险用户。其中 ans 相当于维护了前一天的风险用户,tmp 通过 ans 以及 当天的新信息确定所有风险用户,再用其更新 ans。最后 set 去重得到最终结果。

这次CSP的大模拟感觉题意简单,操作挺少,应该挺好AC的。但当天考试正好是数模国赛的最后一下午。为了赶数模只草草写完前两题就润了,好后悔qwq

Code

#include<bits/stdc++.h>

using namespace std;

inline int read()
{
	int x = 0, f = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9')
	{
		if(ch == '-') f = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9')
	{
		x = (x<<1) + (x<<3) + (ch^48);
		ch = getchar();
	}
	return x*f;
}

struct MES
{
	int d, u, r;
};
int n;

map< pair<int, int>, bool> mp;
vector <MES> ans;

int main()
{
	cin >> n;
	for(int now = 0; now < n; now++)
	{
		int r = read(), m = read();
		for(int i = 1; i <= r; i++)
		{
			int p = read();
			for(int j = now; j < now + 7; j++)
			{
				mp[make_pair(p, j)] = true;
			}
		}
		vector <MES> tmp;
		for(auto it = ans.begin(); it != ans.end(); it++)
		{
			bool flag = true;
			if(now - it->d >= 7) continue; //注意!!!
			for(int i = it->d; i <= now; i++)
			{
				if(!mp.count(make_pair(it->r, i)))
				{
					flag = false;
					break;
				}
			}
			if(flag)
			{
				tmp.push_back(*it);
			}
		}
		ans.clear();
		ans = tmp;
		for(int i = 1; i <= m; i++)
		{
			int d = read(), u = read(), r = read();
			bool flag = true;
			if(now - d >= 7) continue; //注意!!!
			for(int j = d; j <= now; j++)
			{
				if(!mp.count(make_pair(r, j)))
				{
					flag = false;
					break;
				}
			}
			if(flag)
			{
				ans.push_back({d, u, r});
			}
		}
		set <int> fin;
		for(auto it = ans.begin(); it != ans.end(); it++)
		{
			fin.insert(it->u);
		}
		cout << now << " ";
		for(auto it = fin.begin(); it != fin.end(); it++)
		{
			cout << *it << " ";
		}
		cout << endl;
	}
	return 0;
}

标签:风险,ch,int,CSP202209,用户,ans,now
From: https://www.cnblogs.com/kevin-chance/p/16753541.html

相关文章