Codevs 队列练习 合并版
来源:互联网 发布:springboot 切面编程 编辑:程序博客网 时间:2024/05/19 22:26
3185 队列练习 1
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold
题目描述 Description
给定一个队列(初始为空),只有两种操作入队和出队,现给出这些操作请输出最终的队头元素。 操作解释:1表示入队,2表示出队
输入描述 Input Description
N(操作个数)
N个操作(如果是入队则后面还会有一个入队元素)
具体见样例(输入保证队空时不会出队)
输出描述 Output Description
最终队头元素,若最终队空,输出”impossible!”(不含引号)
样例输入 Sample Input
3
1 2
1 9
2
样例输出 Sample Output
9
数据范围及提示 Data Size & Hint
对于100%的数据 N≤1000 元素均为正整数且小于等于100
1 #include<iostream> 2 using namespace std; 3 int a[1010],n; 4 int main() 5 { 6 int x,y,head=0,tail=0; 7 cin>>n; 8 for(int i=1;i<=n;i++) 9 {10 cin>>y;11 if(y==1)12 {13 cin>>x;a[tail]=x;14 tail++;15 }16 if(y==2)17 {18 head++; 19 }20 }21 if(head==tail) cout<<"impossible!";22 else cout<<a[head];23 return 0;24 }
3186 队列练习 2
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold
题目描述 Description
(此题与队列练习1相比改了2处:1加强了数据 2不保证队空时不会出队)
给定一个队列(初始为空),只有两种操作入队和出队,现给出这些操作请
输出最终的队头元素。 操作解释:1表示入队,2表示出队
输入描述 Input Description
N(操作个数)
N个操作(如果是入队则后面还会有一个入队元素)
具体见样例(输入保证队空时不会出队)
输出描述 Output Description
最终队头元素,若最终队空,或队空时有出队操作,输出”impossible!”(不含引号)
样例输入 Sample Input
3
1 2
2
2
样例输出 Sample Output
impossible!
数据范围及提示 Data Size & Hint
对于100%的数据 N≤100000 元素均为正整数且小于等于10^8
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 using namespace std; 5 int a[200000],n; 6 int main() 7 { 8 int x,y,head=0,tail=0; 9 cin>>n;10 for(int i=1;i<=n;i++)11 {12 scanf("%d",&y);13 if(y==1)14 {15 scanf("%d",&x);16 a[tail]=x;17 tail++;18 }19 if(y==2)20 {21 head++;22 }23 if(head>tail) {24 printf("impossible!\n");25 return 0;26 }27 }28 if(head>tail) {29 printf("impossible!\n");30 }31 else 32 printf("%d\n",a[head]);33 return 0;34 }
3187 队列练习 3
时间限制: 1 s空间限制: 128000 KB 题目等级 : 钻石 Diamond
题目描述 Description
0 0
- Codevs 队列练习 合并版
- codevs 3186 队列练习2
- codevs 3185 队列练习1
- 【codevs 3185】队列练习1
- 【codevs 3186】队列练习2
- 【codevs 3187】队列练习3
- 【codevs 1063】合并果子
- CODEVS 1063合并果子
- codevs 1063 合并果子
- CODEVS 1063 合并果子
- Codevs 1063 合并果子
- codevs 1048 合并石子
- SDUT OJ 树-堆结构练习——合并果子之哈夫曼树 C++优先队列练习
- CodeVS 1063 合并果子 题解
- 队列练习
- CODEVS 3139 栈练习3
- DFS练习-codevs-1116四色问题
- codevs线段树练习3
- 重启微博之路
- Codevs 1051 接龙游戏
- JavaScript Map
- COdevs 1531 山峰
- 传递闭包
- Codevs 队列练习 合并版
- Codevs 3269 混合背包
- Codevs 1005 生日礼物
- Codevs 2956 排队问题
- Codevs 1557 热浪
- POJ 2395 Out of Hay
- Tarjan 算法 自学整理
- 洛谷 P 1330 封锁阳光大学
- http://www.iteye.com/problems/64642