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 ...
随机推荐
- NO.5:自学python之路------标准库,正则表达式
引言 时间过的好快呀,终于6级也考完了,学习Python的进度也得赶赶了.好的开始这一周的内容. 正文 模块 模块的本质就是‘.py’结尾的文件,它可以用来从逻辑上组织Python代码,它可以是变量. ...
- python正则表达式,以及应用[下载图片]
regular expresion由一系列特定字符及其组合成的字符串,用来对目标字符串进行过滤操作.. re相关知识点 python正则表达式库为re,用import re导入,在然后用re.comp ...
- 看oracle的sid
ps -ef|grep pmon 可以从进程名字里看到 也可以通过 sqlplus / as sysdbashow parameter instance_name
- wordpress登录密码框明文显示最后一个输入的字符
wordpress登录密码框明文显示最后一个输入的字符 (function(a){a.fn.dPassword=function(c){var e={interval:200,duration:100 ...
- 第十次作业psp
psp 进度条 博文累积折线图 代码累积折线图 psp饼状图
- 2017-2018-2 1723 『Java程序设计』课程 结对编程练习_四则运算
一.结对对象 姓名:侯泽洋 学号:20172308 担任角色:驾驶员(侯泽洋) 伙伴第一周博客地址 二.本周内容 1.程序需求 (1).自动生成题目 可独立使用(能实现自己编写测试类单独生成题目的功能 ...
- maven 阿里仓库配置文件
<?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Soft ...
- 使你的WebService可以远程调试点击“调用”
默认发布webservice时,只有在本机访问某个方法时可以点击调用,如果有参数时,也可以输入参数值,但是如果是远程访问时,点击进入一个服务时,是不显示“调用”和输入参数框的. 原来web.confi ...
- 1001. A+B Format (20)的解题思路以及多源代码文件的尝试编写
前言 这几天刚学了多源代码文件的编译,因为想尝试使用一下这种方法,所以想用此编写这次作业的程序.正好可以learning by doing,在做当中学习新知识.(编译器为Dev-C++) github ...
- Maven教程--02设置Maven本地仓库|查看Maven中央仓库
一:设置Maven本地仓库 Maven默认仓库的路径:~\.m2\repository,~表示我的个人文档:例如:C:\Users\Edward\.m2\repository:如下图: Maven的配 ...