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 ...
随机推荐
- Ruby知识点一:方法
1.实例方法 接收者是对象本身的方法 2.类方法 接收者是类本身的方法,调用类方法时,可以使用::或者.两个符号. 类名.方法名 类名::方法名 3.函数式方法 没有接收者(接收者省略而已)的方法 4 ...
- 服务端模版注入漏洞检测payload整理
服务端模版注入漏洞产生的根源是将用户输入的数据被模版引擎解析渲染可能导致代码执行漏洞 下表涵盖了java,php,python,javascript语言中可能使用到的模版引擎,如果网站存在服务端模版注 ...
- Tornado之笔记集合
目录 一.基本使用 二.路由系统 三.视图函数 四.模版语言 五.cookie 六.CSRF 七.文件上传 八.异步非阻塞 九.RESTFUL 十.自定义组件 一.基本使用 1.最简使用 import ...
- Visual Studio AI配置环境
参考链接:http://www.cnblogs.com/ms-uap/p/9123033.html 背景: 1.能联网的电脑:Win7 64 SP1 2.鼠标.键盘.显示器好使 3.已安装VS2010 ...
- Daily Scrum6 11.10
今日任务: 徐钧鸿:codingcook的sql相关内容,并在进行复查张艺:继续用户管理部分代码黄可嵩:学习搜索的知识,继续进行搜索的移植和响应徐方宇:动态控件和页面间信息传递以及页面响应事件机制试验 ...
- 20162328蔡文琛 week09 大二
20162328蔡文琛 大二week09 教材学习内容总结 堆是一棵完全二叉树,其中每个元素大于等于其所有子节点的值. 向堆中添加一个元素的方法是,首先将这个元素添加为叶节点然后将其向上移动到合适的位 ...
- 2018软工实践—Beta冲刺(5)
队名 火箭少男100 组长博客 林燊大哥 作业博客 Beta 冲鸭鸭鸭! 成员冲刺阶段情况 林燊(组长) 过去两天完成了哪些任务 协调组内工作 协助数据库完善搭建 展示GitHub当日代码/文档签入记 ...
- 剑指offer:替换空格
题目描述: 请实现一个函数,将一个字符串中的每个空格替换成“%20”.例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy. 思路: 一开始没理解,函数中 ...
- 评论alpha发布以及PSP
讲解顺序: 1. 俄罗斯方块 武志远 俄罗斯方块有自己新颖的玩法加在里面 ,可以进行游戏,界面友好但不美观,与传统玩法相比增加了经验值,这是一个很好的创意,游戏运行也很流畅,并找到两名同学现场体 ...
- yii 验证码 CCaptcha的总结(转)
今天用到yii的验证码 ccaptcha,经过在网上搜寻 找到以下例子: 1.在controller中加入代码 (1)启用 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 &l ...