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

Codeforces Round 1029 (Div. 3)

Dashboard - Codeforces Round 1029 (Div. 3) - Codeforces

https://codeforces.com/contest/2117/problem/A

遇到第一个门之后,使用按钮,直接把索引跳到+x后,再判断后面是否有门

#include<bits/stdc++.h>
using namespace std;int main()
{int t;cin >> t;while (t--){int a, b;cin >> a >> b;vector<int>arr(a);int flag = 1;for (int i = 0; i < a; i++){cin >> arr[i];}int c = 1;for (int i = 0; i < a; i++){if(arr[i]==1&&c==0){flag = 0;}if (arr[i] == 1&&c==1){c = 0;i = i+b-1;}}if (flag){cout << "YES" << "\n";}else{cout << "NO" << "\n";}}}

Problem - B - Codeforces

不难发现规律,先左后右,一次从0到n,往中心填数

#include<bits/stdc++.h>
using namespace std;int main()
{int t;cin >> t;while (t--){int n;cin >> n;vector<int>arr(n);int left = 0;int right = n - 1;int now = 1;while (1){arr[left] = now;now++;arr[right] = now;now++;right--;left++;if (left == right){arr[left] = now;break;}else if (left > right){break;}}for (int i = 0; i < n; i++){cout << arr[i] << " ";}cout << "\n";}}

Problem - C - Codeforces

想第一版代码的时候,想的很复杂:

我们认为第一个数就是第一个酷数组,然后用map保存,当往后访问的时候,再次遇到a,让map[a] = 0;假设移动了m个单位,我们用for(int i = 0;i<m;i++)让这段区间的数进入map,再开始

简洁解法:

稍微思考,不难发现,后面的酷数组一定包含前面所有酷数组的元素。

 创建两个set,第一个收录上一个酷数组的元素,用来erase,当size为0时,说明下一个酷数组已经出现。

第二个收录当前酷数组的元素,用insert,当这个元素不在set中,就直接insert。

每当第一个set清空时,把第二个set数据给第一个

来看代码:

#include<bits/stdc++.h>
using namespace std;int main()
{int t;cin >> t;while (t--){int n;cin >> n;vector<int>arr(n);for (int i = 0; i < n; i++){cin >> arr[i];}set<int>now, last;//一开始 只有第一个now.insert(arr[0]);last = now;int cnt = 1;for (int i = 1; i < n; i++){auto it = last.find(arr[i]);if (it != last.end()){last.erase(it);if (last.empty()){cnt++;last = now;}}else{now.insert(arr[i]);}}cout << cnt << "\n";}}

http://www.xdnf.cn/news/13467.html

相关文章:

  • C语言数据结构笔记6:使用宏和指针来设置和操作嵌套在结构体中的联合体数组的特定位
  • OC学习—Block初探(简易版)
  • 【实战指南】前端项目Nginx配置全流程:从打包部署到解决跨域/路由循环问题
  • 在C# 中使用建造者模式
  • 算法题(167):FBI树
  • Oracle日志体系和遇到问题后日志排查路径
  • 行为模式-责任链模式
  • 进行性核上性麻痹健康护理指南:全方位照护之道
  • Pytorch 的编程技巧
  • Java八股文——Spring「Spring 篇」
  • 5.4.2树、森林与二叉树的转换
  • 今日行情明日机会——20250611
  • Android GreenDAO 通过 Key 查询数据库数据慢问题优化
  • 13.自治系统路由计算题
  • Node.js:开启现代服务器端编程的新篇章
  • h5fortran 简介与使用指南
  • 新能源知识库(36)什么是BMU
  • 51LA数据分析遇瓶颈?免费统计工具——悟空统计
  • 大话软工笔记—工程分解
  • GlusterFS分布式文件系统
  • 【Keepalived】Keepalived-2.3.4恢复对RHEL7的支持
  • 第七章: SEO与渲染方式 三
  • (十一)优化算法(Optimization):深度学习训练中的收敛性分析与泛化理论
  • 鹰盾视频加密器Windows播放器AI溯源水印技术方案解析
  • ros2--Sophus
  • “新液冷”破题“智算热”,数字经济低碳化发展新解
  • 【Linux】Linux 操作系统 - 22 , 软硬链接详解 !
  • 104.解决在流式回答功能实现之后上传附件功能失效bug之前端处理
  • DAY 28 类的定义和方法
  • 三代社保卡全字段识别-社保卡识别软件-社保卡识别接口集成