当前位置: 首页 > news >正文

博客网站素材什么是网络营销什么是传统营销

博客网站素材,什么是网络营销什么是传统营销,北京网站建设116net,网站的费用2022–09-3 防疫大数据 STL大模拟 使用map优化索引 2022–09-3 防疫大数据 STL大模拟 使用map优化索引基本思路遇到的问题(学到的东西)感悟完整代码 2022–09-3 防疫大数据 STL大模拟 使用map优化索引 这题中规中矩,不算太难也不算太简单&am…

2022–09-3 防疫大数据 STL大模拟 使用map优化索引

  • 2022–09-3 防疫大数据 STL大模拟 使用map优化索引
    • 基本思路
    • 遇到的问题(学到的东西)
    • 感悟
    • 完整代码

2022–09-3 防疫大数据 STL大模拟 使用map优化索引

这题中规中矩,不算太难也不算太简单,难点就是能否理清逻辑,注意细节 (这题好坑找bug找了好久啊也怪自己太傻),但是这些错,自己不写是不知道的,还得自己找出来,加深自己的印象。

基本思路

做csp的大模拟题的基本思路就是,将给的数据用一定的数据结构存起来,这个数据结构要方便后边搜索,然后题目的问题一般本质就是搜索。所以要仔细读题,如果给出了形式化描述(数学表达式)尽量用题目给的表达式来写代码,这样错的概率更低

针对于本题,题目的数据分为两类,一类是城市数据,另一类游客的到访数据,然后题目就差不多是求他们两个的交集(用题目给定的规则来交)。

城市的数据是 给出有风险的城市的集合,风险的开始日期是给出数据的日期

游客的到访数据 是给出到访的时间 到访的地点 游客id

注意游客这里就有两个日期:收到到访数据的日期, 和访问的日期

我们分别建立索引,城市用城市id建立索引、游客用收到数据的日期建立索引,然后搜索的时候,就会加快速度找到。

然后根据题目的要求来匹配

形式化地,在 d 日生成的风险名单中,用户 u 被列入风险名单,当且仅当:

存在一个日期 d 0 ∈ ( d − 7 , d ] d_0 \in (d-7,d] d0(d7,d],存在一条 d 0 d_0 d0 日收到的漫游数据 < d 1 , u , r > <d_1,u,r> <d1,u,r>,使得

  • d 1 ∈ ( d − 7 , d ] d_1 \in (d-7,d] d1(d7,d],并且
  • 对于任意的 D ∈ [ d 1 , d ] D \in [d_1,d] D[d1,d],地区 r 在 D 日处于风险状态。

所以就是要遍历d日的前6天的到访数据,然后判断该地是不是风险地区在那个区间上。

遇到的问题(学到的东西)

这题随便一写什么都不用考虑,只要模拟出来了基本都是40分,然后我一开始就是40分,然后怎么也找不到bug,然后逐渐找到了几个bug但是还是40分,最终参考别人的代码还是找到了bug,考场上要是找不到只能认栽了。

  1. 风险地区的风险区间合并问题

这个问题我一开始,没有注意到,就是要把风险区间有交集的进行合并,但是这个合并的逻辑有了一点点问题,下面会提到

  1. 风险地区的风险区间合并问题的实现

实现的过程中是后一个插入前一个的,但是会导致最后一个没有插入

修改之前

    // 合并一下区间for (auto item : place_time){struct places temp;temp.length = -1; // 标记为还没初始化for (auto p : item.second){if (temp.length != -1 && p.day >= temp.day && p.day <= temp.day + temp.length){int end1 = p.day + p.length - 1;int end2 = temp.day + temp.length - 1;temp.length += end1 - end2;}else{place_time2[item.first].push_back(temp);temp = p;}}}

并且会报错,因为没有初始化的temp也会被插入

修改后的

    // 合并一下区间for (auto item : place_time){struct places temp;temp.length = -1; // 标记为还没初始化for (auto p : item.second){if (temp.length != -1 && p.day >= temp.day && p.day <= temp.day + temp.length){int end1 = p.day + p.length - 1;int end2 = temp.day + temp.length - 1;temp.length += end1 - end2;}else{if (temp.length != -1)place_time2[item.first].push_back(temp);temp = p;}}if (temp.length != -1)place_time2[item.first].push_back(temp);}
  1. 判断是不是风险用户的问题

这点一开始是自己找的规律然后按着自己想到去判断的,没想到的少了一些条件,然后补上了,但是仍然是40分,之后百思不得其解

  1. 区间合并的逻辑问题

原来这个区间合并,不只是有交集的区间合并,就算是没有交集但是中间没有间隔的区间也要合并的,这点我是看了别人的代码才想到的,考试要是碰见这个直接就g了

修改之前

    // 合并一下区间for (auto item : place_time){struct places temp;temp.length = -1; // 标记为还没初始化for (auto p : item.second){if (temp.length != -1 && p.day >= temp.day && p.day <= temp.day + temp.length-1){int end1 = p.day + p.length - 1;int end2 = temp.day + temp.length - 1;temp.length += end1 - end2;}else{if (temp.length != -1)place_time2[item.first].push_back(temp);temp = p;}}if (temp.length != -1)place_time2[item.first].push_back(temp);}

修改之后

    // 合并一下区间for (auto item : place_time){struct places temp;temp.length = -1; // 标记为还没初始化for (auto p : item.second){if (temp.length != -1 && p.day >= temp.day && p.day <= temp.day + temp.length){int end1 = p.day + p.length - 1;int end2 = temp.day + temp.length - 1;temp.length += end1 - end2;}else{if (temp.length != -1)place_time2[item.first].push_back(temp);temp = p;}}if (temp.length != -1)place_time2[item.first].push_back(temp);}

就是这个

            if (temp.length != -1 && p.day >= temp.day && p.day <= temp.day + temp.length)

改变了

之后就可以拿到了100分,

在这里插入图片描述
5. 还学到了使用freopen()

如果你的csp考场上 无法往终端里复制数据,可以直接使用

freopen("1.txt", "r", stdin);

注意1.txt是相对路径,可以替换成你的输入的路径,然后其他什么都不用改变,就可以了。

感悟

这题竟然是没有一次做出来,而且还是看了别人的思路才找出来问题的。中间其实改了很多次,就是没有改到点上,以后联系的时候,如果不是真错了,就不改,或者要保留原版的,不然没办法真正的找到错误。

如果考试中有这中情况,得把每个实现的点都列出来,然后逐个分析,不能一带而过,想一想真的是这样的吗?尤其是写if的时候的。而且不能只盯着一个点不看别的,浪费时间又找不到错误。

完整代码

#include <bits/stdc++.h>
using namespace std;
int n;
struct dayget
{int u;int day; // 到达的一天
};
struct places
{int id;     // 地方的idint day;    // 风险的开始日期int length; // 风险的长度
};
unordered_map<int, unordered_map<int, vector<dayget>>> arrive; // arrive[i][j]第i天收到j地到的用户的集合
unordered_map<int, vector<places>> place_time;                 // place_time[i] id为i的地方的风险时间片段的集合
unordered_map<int, vector<places>> place_time2;                // place_time[i] id为i的地方的风险时间片段的集合
unordered_set<int> risks[1010];                                // 存储每天的风险用户
bool searchIsDanger(int d1, int d, vector<places> dage)
{for (int i = 0; i < dage.size(); i++){if (dage[i].day <= d1 && dage[i].day + dage[i].length - 1 >= d){return true;}}return false;
}
int main()
{// freopen("1.txt", "r", stdin);cin >> n;for (int i = 0; i < n; i++){int r, m;cin >> r >> m;for (int j = 0; j < r; j++){int p;cin >> p;struct places t = {p, i, 7};place_time[p].push_back(t);}for (int j = 0; j < m; j++){int d, u, r1;cin >> d >> u >> r1;struct dayget t = {u, d};if (d < i - 6) // 如果收到收到消息的是7天之前的就不要了continue;arrive[i][r1].push_back(t);}}// 合并一下区间for (auto item : place_time){struct places temp;temp.length = -1; // 标记为还没初始化for (auto p : item.second){if (temp.length != -1 && p.day >= temp.day && p.day <= temp.day + temp.length){int end1 = p.day + p.length - 1;int end2 = temp.day + temp.length - 1;temp.length += end1 - end2;}else{if (temp.length != -1)place_time2[item.first].push_back(temp);temp = p;}}if (temp.length != -1)place_time2[item.first].push_back(temp);}for (int d = 0; d < n; d++){for (int i = max(0, d - 6); i <= d; i++){for (auto c : arrive[i]) // 分析第i天到访的所有地方{int r = c.first;for (auto user : c.second) // 到访r地的所有的人 然后判断是不是该设定为风险人员{int d1 = user.day;if (d1 >= d - 6 && searchIsDanger(d1, d, place_time2[r])){risks[d].insert(user.u);}}}}}for (int i = 0; i < n; i++){cout << i << ' ';vector<int> risk1(risks[i].begin(), risks[i].end());sort(risk1.begin(), risk1.end());for (auto item : risk1){cout << item << ' ';}cout << endl;}
}
http://www.yayakq.cn/news/921519/

相关文章:

  • 怎么去做一个网站网站的建设费用
  • 织梦只显示网站首页世界互联网峰会官网
  • 网站域名推广表格制作手机软件
  • 临沂网站建设求职简历wordpress 链接提交表单
  • 网站百度商桥新风向网站建设
  • 企业网站建设文章wordpress图片友情链接
  • 网站地图怎么样做更利于收录做棋牌网站违法
  • 建设厅安全证考试报名在哪个网站重庆做网站seo优化选哪家好
  • 天津网站建设方案1核做网站
  • 软件开发 系统开发 网站开发服务切图网站建设
  • 糕点网站策划书数据中台厂商
  • 企业做网站多少钱小程序管理平台
  • 网站推广的工具wordpress的网站后台
  • 个人免费建站的网站天津网站备案在哪照相
  • 网站制作验收单wordpress gii插件
  • 织梦网站一排4张图片南宁市建设处网站
  • 专业的移动客户端网站建设浙江信息港网
  • 网站如何做快照c 微信小程序开发教程
  • 主流建站开源程序有哪些网站优化 情况
  • 营销型网站建设一般包含哪些内容网站建设临沂
  • 网站怎么做导航wordpress存档显示文章所有内容
  • 搭建微网站的基本流程北京公司名称及地址大全
  • 响应式全屏网站模板wordpress阶梯插件
  • 四川北路街道网站建设中职国示范建设网站
  • 成都游戏网站开发网站建设要达到什么水平
  • 做外贸 上国外网站wordpress 实现 功能
  • 关键词挖掘网站济南百度公司做网站吗
  • 广州网站设计十年乐云seo泰和县网站免费建站
  • 网站做受网站南京seo优化公司
  • 建网页还是网站企业邮箱忘记密码怎么找回