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 ...
随机推荐
- 【视频编解码·学习笔记】12. 图像参数集(PPS)介绍
一.PPS相关概念: 除了序列参数集SPS之外,H.264中另一重要的参数集合为图像参数集Picture Paramater Set(PPS). 通常情况下,PPS类似于SPS,在H.264的裸码流中 ...
- IOS git 删除仓库 新建仓库 提交 合并 操作 码云
HDHaoShaoPengdeiMac:~ hdhaoshaopeng$ defaults write com.apple.finder AppleShowAllFiles TRUE HDHaoSha ...
- 如何使用g++编译调用dll的c++代码
本文将有以下4个部分来讲如何使用g++编译调用dll的c++代码. 1.如何调用dll 2.动态链接和静态链接的区别 3.g++的编译参数以及如何编译调用dll的c++代码 4.总结 1.如何调用dl ...
- 爱码室Crawler & classification module项目工作分配
项目情况 爬虫项目是上届学生遗留下来的项目,他们已经实现了基础的功能,而我们来负责完善,主要需要解决的问题是怎么让爬虫脱离爬和停的繁琐指令,更加的智能化.所以我们的计划是在前人的源码基础上,加以修改测 ...
- 实验三:敏捷开发与XP实践
Java实验三报告 一. 实验内容 (一)敏捷开发与XP 内容:1.敏捷开发(Agile Development)是一种以人为核心.迭代.循序渐进的开发方法. 2.极限编程(eXtreme Pro ...
- bata3
目录 组员情况 组员1(组长):胡绪佩 组员2:胡青元 组员3:庄卉 组员4:家灿 组员5:凯琳 组员6:翟丹丹 组员7:何家伟 组员8:政演 组员9:黄鸿杰 组员10:刘一好 组员11:何宇恒 展示 ...
- Prism6下的MEF:添加Logger
上篇已经简单的构建了一个Prism的程序,现在我们需要添加一个Logger,Prism本身自带一个功能简单的TextLogger,但是我们希望能用.Net常用的Log4net.所以我们需要重载掉Boo ...
- 转 C#高性能Socket服务器SocketAsyncEventArgs的实现(IOCP)
原创性申明 本文作者:小竹zz 博客地址:http://blog.csdn.net/zhujunxxxxx/article/details/43573879转载请注明出处引言 我一直在探寻一个高性能 ...
- 用css 实现凹陷的线条
box-shadow: 0 1px 0 rgba(255,255,255,0.2) inset,0 -1px 0 rgba(0,0,0,.2) inset; 因为颜色为透明颜色,所以颜色是什么样的,不 ...
- DRBD 实验
跨主机的块设备镜像系统,工作在内核中完成 drbd工作原理:客户端发起一个写操作的系统调用给文件系统,写请求再到达内核缓冲区,最到达DRBD模块,此时drbd会复制写入磁盘的数据,且进行两步操作,第一 ...