POJ 2823
来源:互联网 发布:pc短信群发软件 编辑:程序博客网 时间:2024/06/08 17:25
题目链接:http://poj.org/problem?id=2823
—————————————————————————————————————
题目关键字:单调队列
—————————————————————————————————————
基本思路:队头删出窗的元素,队尾插入新的元素。且不如当前值的都在队尾被删掉。
—————————————————————————————————————
源代码:
#include<stdio.h>int n = 0,k = 0;int val[1000010];int que[1000010],h = 0,t = 0;int camp(int a,int b,int i){ if(i == 1) { if(a>b) return 0; else return 1; } else { if(a>b) return 1; else return 0; }}void find(int p){ int l = 0, r = 0,m = 0; int i = 0; que[0] = 0; h = 0;t = 0; for(i = 1;i<=n;i++) { l = h;r = t; if(h<t && i-que[h]+1>k) h++; while(h<t && camp(val[i],val[que[t-1]],p)) t--; que[t++] = i; if(i>=k) printf("%d ",val[que[h]]); } printf("\n");}int main(){ int i = 0; scanf("%d%d",&n,&k); for(i = 1;i<=n;i++) scanf("%d",&val[i]); find(1); find(2); return 0;}
- poj 2823
- POJ 2823
- poj 2823
- POJ 2823
- poj 2823
- POj 2823
- POJ 2823
- POJ 2823
- poj-2823
- POJ 2823
- poj 2823
- poj 2823
- poj 2823
- 【POJ】2823
- POJ 2823 Sliding Window
- poj 2823 Sliding Window
- Poj 2823 (单调队列)
- poj 2823【单调队列】
- hdu3047
- strlen strcmp strcpy strcat strchr strstr 基础实现
- android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byte
- Hypertable - 架构
- FFMpeg框架代码阅读
- POJ 2823
- Textbox控件插入换行符的问题
- HDU--1198Farm Irrigation
- 图的存储与遍历
- Linux学习笔记(十三)
- Js 知识总结
- js 模式设计之单例
- js数组操作
- 写个servlet,用来导数据到word的,结果在ie8的情况下闪退了,在ie9情况下不会,郁闷啊