2018 “百度之星”程序设计大赛 - 初赛(A)度度熊学队列 list rope
c++ list使用
- #include <cstdio>
- #include <cstdlib>
- #include <cmath>
- #include <cstring>
- #include <time.h>
- #include <string>
- #include <set>
- #include <map>
- #include <list>
- #include <ext/rope>
- #include <stack>
- #include <queue>
- #include <vector>
- #include <bitset>
- #include <algorithm>
- #include <iostream>
- using namespace std;
- #define ll long long
- #define minv 1e-6
- #define inf 1e9
- #define pi 3.1415926536
- #define E 2.7182818284
- const ll mod=1e9+;//
- const int maxn=;
- using namespace __gnu_cxx;
- char ch;
- void read(int &x){
- ch = getchar();x = ;
- for (; ch < '' || ch > ''; ch = getchar());
- for (; ch >='' && ch <= ''; ch = getchar()) x = x * + ch - '';
- }
- list<int>f[maxn];
- int main()
- {
- int n,q,mode,u,w,val,v,i;
- while (~scanf("%d%d",&n,&q))
- {
- for (i=;i<=n;i++)
- f[i].clear();
- while (q--)
- {
- read(mode);
- if (mode==)
- {
- read(u),read(w),read(val);
- if (w)
- f[u].push_back(val);
- else
- f[u].push_front(val);
- }
- //
- else if (mode==)
- {
- read(u),read(w);
- if (f[u].empty())
- printf("-1\n");
- else
- {
- if (w)
- {
- printf("%d\n",f[u].back());
- f[u].pop_back();
- }
- else
- {
- printf("%d\n",f[u].front());
- f[u].pop_front();
- }
- }
- }
- //
- else
- {
- read(u),read(v),read(w);
- if (w)
- reverse(f[v].begin(),f[v].end());
- f[u].splice(f[u].end(),f[v]);
- //or
- // if (w)
- // f[u].insert(f[u].end(),f[v].rbegin(),f[v].rend());
- // else
- // f[u].insert(f[u].end(),f[v].begin(),f[v].end());
- f[v].clear();
- }
- }
- }
- return ;
- }
- /*
- 2 30
- 1 1 0 123
- 1 1 0 1234
- 1 2 1 2333
- 1 2 1 23333
- 1 2 1 233333
- 1 2 1 2333333
- 1 2 1 23333333
- 2 2 0
- 2 2 1
- 3 1 2 1
- 2 1 1
- 2 1 1
- 2 1 1
- 2 1 1
- 2 1 1
- 2 1 1
- 3 1 5 0
- 1 5 1 1
- 2 5 1
- */
用rope超时了
- #include <cstdio>
- #include <cstdlib>
- #include <cmath>
- #include <cstring>
- #include <time.h>
- #include <string>
- #include <set>
- #include <map>
- #include <list>
- #include <ext/rope>
- #include <stack>
- #include <queue>
- #include <vector>
- #include <bitset>
- #include <algorithm>
- #include <iostream>
- using namespace std;
- #define ll long long
- #define minv 1e-6
- #define inf 1e9
- #define pi 3.1415926536
- #define E 2.7182818284
- const ll mod=1e9+;//
- const int maxn=;
- using namespace __gnu_cxx;
- void read(int &x){
- char ch = getchar();x = ;
- for (; ch < '' || ch > ''; ch = getchar());
- for (; ch >='' && ch <= ''; ch = getchar()) x = x * + ch - '';
- }
- rope<int>f[maxn],ff[maxn];
- int main()
- {
- int n,q,mode,u,w,val,v,i;
- while (~scanf("%d%d",&n,&q))
- {
- for (i=;i<=n;i++)
- f[i].clear(),ff[i].clear();
- while (q--)
- {
- read(mode);
- if (mode==)
- {
- read(u),read(w),read(val);
- if (w==)
- {
- f[u].push_back(val);
- ff[u].insert(,val);
- }
- else
- {
- f[u].insert(,val);
- ff[u].push_back(val);
- }
- }
- else if (mode==)
- {
- read(u),read(w);
- if (f[u].empty())
- printf("-1\n");
- else
- {
- if (w==)
- {
- printf("%d\n",f[u].at(f[u].size()-));
- f[u].erase(f[u].size()-,);
- ff[u].erase(,);
- }
- else
- {
- printf("%d\n",f[u].at());
- f[u].erase(,);
- ff[u].erase(f[u].size()-,);
- }
- }
- }
- else
- {
- read(u),read(v),read(w);
- if (w==)
- {
- f[u].append(f[v]);
- ff[u]=ff[v]+ff[u];
- f[v].clear();
- ff[v].clear();
- }
- else
- {
- f[u].append(ff[v]);
- ff[u]=f[v]+ff[u];
- f[v].clear();
- ff[v].clear();
- }
- }
- }
- }
- return ;
- }
2018 “百度之星”程序设计大赛 - 初赛(A)度度熊学队列 list rope的更多相关文章
- HDU6383 2018 “百度之星”程序设计大赛 - 初赛(B) 1004-p1m2 (二分)
原题地址 p1m2 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total ...
- HDU6380 2018 “百度之星”程序设计大赛 - 初赛(B) A-degree (无环图=树)
原题地址 degree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Tot ...
- 2018 “百度之星”程序设计大赛 - 初赛(A)
第二题还算手稳+手快?最后勉强挤进前五百(期间看着自己从两百多掉到494名) 1001 度度熊拼三角 (hdoj 6374) 链接:http://acm.hdu.edu.cn/showprob ...
- 【2018 “百度之星”程序设计大赛 - 初赛(B)-1004】p1m2(迷之二分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6383 题目就是让你求一个整数数组,在进行任意元素 + 1. - 2 操作后,请问在所有可能达到的稳定数 ...
- 【2018 “百度之星”程序设计大赛 - 初赛(B)- 1001】degree
Problem Description 度度熊最近似乎在研究图论.给定一个有 N 个点 (vertex) 以及 M 条边 (edge) 的无向简单图 (undirected simple graph) ...
- 2018 “百度之星”程序设计大赛 - 初赛(B)
degree Accepts: 1581 Submissions: 3494 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 1310 ...
- 2017"百度之星"程序设计大赛 - 资格赛 1002 度度熊的王国战略
全局最小割 Stoer-Wagner (SW算法)优化 优化吃藕了,感谢放宽时限,感谢平板电视 (pb_ds) #include <iostream> #include <cstdi ...
- HDU 6118 度度熊的交易计划 【最小费用最大流】 (2017"百度之星"程序设计大赛 - 初赛(B))
度度熊的交易计划 Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 6119 小小粉丝度度熊 【预处理+尺取法】(2017"百度之星"程序设计大赛 - 初赛(B))
小小粉丝度度熊 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
随机推荐
- 搬运_maven打包
参考文章 利用Maven插件将依赖包.jar/war包及配置文件输出到指定目录 <build> <plugins> <plugin> <groupId> ...
- Qt tableWidget 空单元格 获取选中行行号
bool focus = tableWidget->isItemSelected(tableWidget->currentItem()); // 判断是否选中一行 Int row1 = t ...
- lscpi命令详解
基础命令学习目录 lspci是一个用来查看系统中所有PCI总线以及连接到该总线上的设备的工具. 命令格式为 lspci -参数 (不加参数显示所有硬件设备) 至于有哪些参数及其详细用法可以看下这篇博客 ...
- python清空列表的方法
1.大数据量的list,要进行局部元素删除,尽量避免用del随机删除,非常影响性能,如果删除量很大,不如直接新建list,然后用下面的方法释放清空旧list. 2.对于一般性数据量超大的list,快速 ...
- 最详细的springmvc-mybatis教程
链接:http://blog.csdn.net/qq598535550/article/details/51703190
- CF 1100C NN and the Optical Illusion(数学)
NN is an experienced internet user and that means he spends a lot of time on the social media. Once ...
- Windows下Visual Studio2017之AI环境搭建
本博客主要包含以下3点: AI简介及本博客主要目的 环境介绍及安装原因 搭建环境及检验是否安装成功 离线模型的训练 时间分配: 时间 时长(分钟) 收集资料+写博客 6.12 11:28-12:2 ...
- Teamproject Week7 --Scrum Meeting #1 2014.10.28
这是团队的第一次会议,具体议题如下: 1)我们明确了团队成员的职责所需: PM职责:根据项目范围.质量.时间与成本的综合因素的考虑,进行项目的总体规划与阶段计划. 控制项目组各成员的工作进度,即时了 ...
- 实验五 — — Java网络编程及安全
java的第五个实验——Java网络编程及安全 北京电子科技学院 实 验 报 告 课程:Java程序设计 班级:1352 姓名:林涵锦 学号:20135213 成绩: ...
- Beta版本发布140字评论
1.飞天小女警组: 礼物挑选工具:系统界面十分新颖,相比于前阶段,增加了账号登陆的功能,并且还根据不同的价位区间添加了礼物的图片,并根据礼物的受欢迎程度添加了top10的功能,并且增加了关于本网站的问 ...