div.2

FZU 2091 播放器

拿一个数组保存播放记录,然后按照操作模拟做,就好啦。为了方便处理,我把第一首歌永久固定在了播放记录的第一项。

 1 #include <stdio.h>
 2 #include <string.h>
 3
 4 const int N = 10000 + 5;
 5 int list[N];
 6 int n,m,tot;
 7
 8 int main() {
 9     int cas;
10     scanf("%d",&cas);
11     while (cas--) {
12         scanf("%d%d",&n,&m);
13         tot = 0;
14         list[tot++] = 0;
15         while (m --) {
16             char str[5];
17             scanf("%s",str);
18             if (strcmp(str,"PRE") == 0) {
19                 if (tot > 1) {
20                     tot --;
21                 }
22             } else if (strcmp(str,"PLAY") == 0) {
23                 int x;
24                 scanf("%d",&x); x --;
25                 if (x != list[tot - 1])
26                     list[tot++] = x;
27             } else {
28                 if (list[tot - 1] != n - 1) {
29                     list[tot] = list[tot - 1] + 1;
30                     tot ++;
31                 }
32             }
33             printf("%d\n",list[tot - 1] + 1);
34         }
35     }
36 }

View Code

div.1

FZU 2022 车站

这个题我是用std::set来做的。所以把这个题当作std::set的推广(雾。

维护一个车站的集合,以及一个相邻车站间距离的集合。

插入和删除,就相应在车站集合里插入/删除,然后更新一下相邻车站间距离的集合。

询问的话,输出车站间距离的集合的最小值即可。

然后距离可能会有一样的,所以维护距离得使用std::multiset(多重集)。

更多的关于set的信息,可以移步看这里,关于multiset的信息,可以看这里。或者百度也行。

时间复杂度O(nlogn)。

 1 #include <stdio.h>
 2 #include <set>
 3
 4 std::set<int> set;
 5 std::multiset<int> dis;
 6
 7 void add(int x) {
 8     if (set.find(x) != set.end()) return ;
 9     std::set<int>::iterator right = set.lower_bound(x);
10     if (right != set.end()) {
11         dis.insert(*right - x);
12     }
13     if (right != set.begin()) {
14         std::set<int>::iterator left = right;
15         left --;
16         dis.insert(x - *left);
17         if (right != set.end()) {
18             dis.erase(dis.find(*right - *left));
19         }
20     }
21     set.insert(x);
22 }
23
24 void del(int x) {
25     if (set.find(x) == set.end()) return ;
26     set.erase(x);
27     std::set<int>::iterator right = set.lower_bound(x);
28     if (right != set.end()) {
29         dis.erase(dis.find(*right - x));
30     }
31     if (right != set.begin()) {
32         std::set<int>::iterator left = right;
33         left --;
34         dis.erase(dis.find(x - *left));
35         if (right != set.end()) {
36             dis.insert(*right - *left);
37         }
38     }
39 }
40
41 int main() {
42     int n;
43     while (scanf("%d",&n) == 1) {
44         set.clear();
45         dis.clear();
46         while (n--) {
47             char str[4];
48             int x;
49             scanf("%s",str);
50             if (str[0] == 'a') {
51                 scanf("%d",&x);
52                 add(x);
53             } else if (str[0] == 'd') {
54                 scanf("%d",&x);
55                 del(x);
56             } else {
57                 if (dis.empty()) {
58                     puts("0");
59                 } else {
60                     printf("%d\n",*dis.begin());
61                 }
62             }
63         }
64     }
65 }

View Code

转载于:https://www.cnblogs.com/zstuACM/p/5084336.html

所谓的日常 #6 - 焚金闕董卓行兇 匿玉璽孫堅背約相关推荐

  1. 人大金仓命令行客户端工具KSQL系列2

    连接与退出 # 本机连接使用以下命令即可,远程连接需要指定 -h -p 参数.具体参数含义请参考上一篇文章<人大金仓命令行客户端工具KSQL系列1>. $ ksql -Usystem -W ...

  2. 人大金仓命令行客户端工具KSQL系列1

    KSQL是什么? ksql是KingbaseES的交互终端,也就是命令行客户端,其作用类似于Oracle的sqlplus.命令行方式的客户端对开发人员可能不太友好,但是对于运维人员来说非常的方便,是必 ...

  3. 使用python爬取三国演义

    此篇使用的是python进行数据爬虫 爬取工具使用的是:bs4,requests 爬取的网站:https://www.shicimingju.com/book/sanguoyanyi.html 爬取的 ...

  4. python中文小写数字排序

    需要用到中文排序,自己用python写了1个,希望能帮到有需要的人. 在网上找了个<三国演义>作为例子,sanfile为需要排序的文件,直接用sorted排序显然不符合我们的逻辑. imp ...

  5. Python爬虫三国演义

    爬取三国全篇内容 定位目标:https://www.shicimingju.com/book/sanguoyanyi.html 在这里插入代码片import requests from bs4 imp ...

  6. Artiely Vue Admin - 基于蚂蚁金服Ant Design构建的高颜值开源管理后台UI框架

    继承 Ant Design 专业美观的优点,支持PC/手机/平板的响应式布局的优秀后台管理系统 UI 框架. 关于 Artiely Vue Admin Ant Design 是阿里巴巴蚂蚁金服团队出品 ...

  7. 从玉农业智能蔬菜技术 农业大健康·林裕豪:中国金控斥资打造

    从玉农业智能蔬菜技术 农业大健康·林裕豪:中国金控斥资打造 新闻中国采编网 中国新闻采编网 谋定研究中国智库网 谋定论道 国研智库 国情讲坛 哲商对话 经信研究 哲商对话 万权采编:开始明确种植蔬菜发 ...

  8. 粤桂协作从玉农业签约 农业大健康·林裕豪:中国金控粤桂帮扶

    粤桂协作从玉农业签约 农业大健康·林裕豪:中国金控粤桂帮扶 新闻中国采编网 中国新闻采编网 谋定研究中国智库网 国研智库 国情讲坛 谋定论道 经信研究 哲商对话 万权采编:11月5日-7日,对话功能性 ...

  9. 从310到蚂蚁森林,蚂蚁金服在线图计算的创新与实践

    蚂蚁金服过去十五年,重塑支付改变生活,为全球超过十二亿人提供服务,这些背后离不开技术的支撑.在 2019 杭州云栖大会上,蚂蚁金服将十五年来的技术沉淀,以及面向未来的金融技术创新和参会者分享.我们将其 ...

最新文章

  1. 抽象工厂模式java_Java之抽象工厂模式(Abstract Factory)
  2. 上云迁移-海量数据迁移解决方案
  3. union万能密码By:dangdang
  4. java多个按钮监听,如何改成监听多个按钮啊用e.getsource()
  5. java thread_Java(多线程Thread)
  6. 数字图像处理(作业三)——孔洞填充+全局阈值+自适应阈值
  7. python nan判断_Python数据分析:Numpy基本操作
  8. 订阅者java,RxJava:“ java.lang.IllegalStateException:只允许一个订阅者!”
  9. 明略数据获 10 亿人民币 C 轮融资,华兴新经济基金、腾讯领投
  10. python - Numpy - matplotlib
  11. org.apache.hadoop.hbase.PleaseHoldException: Master is initializing
  12. 回顾:饶毅教授的一次采访
  13. AlexNet、VGG16、ResNet网络结构图
  14. 后缀树后缀数组LCP
  15. 裂变海报设计的落地干货,为什么海报在裂变活动中这么重要?
  16. 最好的开源网络入侵检测工具
  17. 共享充电宝的终局:金钱游戏
  18. 【企业邮箱注册】管理员如何设置定期修改密码?
  19. FineReport——登录不到决策系统
  20. 爬取凤凰网站财经类的新闻,函数时编程,可全部实现,由于内容量大,需要时间太长,服务器会禁止,为了防止,可以将time.sleep()设置的时间长点...

热门文章

  1. 《走出软件作坊》读后感
  2. [文章存档]Azure上部署的java app在向第三方服务传送中文时出现乱码
  3. Python攻克之路-高阶函数
  4. [fzu 2273]判断两个三角形的位置关系
  5. js——引用类型和基本类型
  6. windows安装dcm4chee 出错 check file system group LOSSY_STORAGE for deletion
  7. Android Studio 安装具体步骤(配图)
  8. HDU 4336 Card Collector(容斥原理+状态压缩)
  9. JavaScript学习笔记(八)--正则表达式
  10. JavaScript学习笔记(六)--数组