【t065】最敏捷的机器人
来源:互联网 发布:大数据事业部职能 编辑:程序博客网 时间:2024/05/04 19:33
Time Limit: 1 second
Memory Limit: 128 MB
【问题描述】
【背景】
Wind设计了很多机器人。但是它们都认为自己是最强的,于是,一场比赛开始了~
【问题描述】
机器人们都想知道谁是最敏捷的,于是它们进行了如下一个比赛。
首先,他们面前会有一排共n个数,它们比赛看谁能最先把每连续k个数中最大和最小值写下来,当然,这些机器人运算速度都很快,
它们比赛的是谁写得快。
但是Wind也想知道答案,你能帮助他吗?
【输入格式】
每组测试数据
第1行为n,k(1<=k<=n<=100000)
第2行共n个数,为数字序列,所有数字均在longint范围内。
【输出格式】
共n-k+1行
第i行为第i~i+k-1这k个数中的最大和最小值
Sample Input
5 3
1 2 3 4 5
Sample Output
3 1
4 2
5 3
【题目链接】:http://noi.qz5z.com/viewtask.asp?id=t065
【题解】
线段树记录一下区间的最大值最小值即可;
【完整代码】
#include <cstdio>#include <cstdlib>#include <cmath>#include <set>#include <map>#include <iostream>#include <algorithm>#include <cstring>#include <queue>#include <vector>#include <stack>#include <string>using namespace std;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define LL long long#define rep1(i,a,b) for (int i = a;i <= b;i++)#define rep2(i,a,b) for (int i = a;i >= b;i--)#define mp make_pair#define pb push_back#define fi first#define se secondtypedef pair<int,int> pii;typedef pair<LL,LL> pll;void rel(LL &r){ r = 0; char t = getchar(); while (!isdigit(t) && t!='-') t = getchar(); LL sign = 1; if (t == '-')sign = -1; while (!isdigit(t)) t = getchar(); while (isdigit(t)) r = r * 10 + t - '0', t = getchar(); r = r*sign;}void rei(int &r){ r = 0; char t = getchar(); while (!isdigit(t)&&t!='-') t = getchar(); int sign = 1; if (t == '-')sign = -1; while (!isdigit(t)) t = getchar(); while (isdigit(t)) r = r * 10 + t - '0', t = getchar(); r = r*sign;}const int MAXN = 1e5+100;const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};const double pi = acos(-1.0);int n,k;int ma[MAXN<<2],mi[MAXN<<2],a[MAXN<<2];void build(int l,int r,int rt){ if (l==r) { scanf("%d",&a[rt]); mi[rt] = ma[rt] = a[rt]; return; } int m = (l+r)>>1; build(lson); build(rson); ma[rt] = max(ma[rt<<1],ma[rt<<1|1]); mi[rt] = min(mi[rt<<1],mi[rt<<1|1]);}int q_ma(int L,int R,int l,int r,int rt){ if (L<=l && r<= R) return ma[rt]; int m = (l+r)>>1; int temp1 = -21e8,temp2 = -21e8; if (L<=m) temp1 = q_ma(L,R,lson); if (m<R) temp2 = q_ma(L,R,rson); return max(temp1,temp2);}int q_mi(int L,int R,int l,int r,int rt){ if (L<=l && r<= R) return mi[rt]; int m = (l+r)>>1; int temp1 = 21e8,temp2 = 21e8; if (L<=m) temp1 = q_mi(L,R,lson); if (m<R) temp2 = q_mi(L,R,rson); return min(temp1,temp2);}int main(){ //freopen("F:\\rush.txt","r",stdin); rei(n);rei(k); build(1,n,1); rep1(i,1,n-k+1) { int L = i,R=i+k-1; printf("%d %d\n",q_ma(L,R,1,n,1),q_mi(L,R,1,n,1)); } return 0;}
0 0
- 【t065】最敏捷的机器人
- 最勇敢的机器人
- 【t064】最勇敢的机器人
- 【t063】最聪明的机器人
- 【t062】最厉害的机器人
- vijos1250 最勇敢的机器人
- [VIJOS1250]最勇敢的机器人
- 人工智能相扑选手令未来的机器人更加聪明敏捷
- Vijos P1250 - 最勇敢的机器人
- 最具影响力的机器人公司
- vijos 1250 最勇敢的机器人
- Vijos P1250 最勇敢的机器人
- Vijos 1249题:最聪明的机器人
- 最勇敢的机器人(Vijos-1250)
- 最热门的敏捷书籍[转]
- 什么样的项目最适合于敏捷开发
- 你心目中最厉害的智能机器人是什么样的?
- 全能的大厨!最酷的厨房机器人
- Linux 挂载其它服务上的文件
- Ubuntu16.04下Apache2.4部署Django1.8.7
- strutsOGNL表达式
- ThreadLocal-------线程范围内的数据共享
- 8大排序算法
- 【t065】最敏捷的机器人
- 滤镜艺术---新海诚(你的名字)滤镜特效的实现解密
- http://www.cnblogs.com/crazy-fox/archive/2012/02/08/2343365.html
- 调整VirtualBox虚拟机分辨率的方法
- matplotlib的常用的两种方式以及pylab
- 跨越障碍,放飞思想
- 金税盘发票查询系统
- SSL P1761 城市问题
- 安装pydev的版本匹配