记录编号 |
313599 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[NOIP 2013]花匠 |
最终得分 |
100 |
用户昵称 |
BillAlen |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.027 s |
提交时间 |
2016-10-01 09:52:10 |
内存使用 |
1.08 MiB |
显示代码纯文本
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#define MAX_N 100000
using namespace std;
unsigned n, rh[MAX_N + 1], tx[MAX_N], ls = -1, sel, selr, dir;
int sgn(int v){ if(v != 0) return v / abs(v); else return 0;}
int main(int argc, char** argv) {
fstream in("FlowerNOIP2013.in", ios::in), out("FlowerNOIP2013.out", ios::out);
cin.rdbuf(in.rdbuf());
cout.rdbuf(out.rdbuf());
cin >> n;
for(int i = 0; i < n; ++i) cin >> rh[i];
// Direction 1
dir = 1;
memset(tx, n, sizeof(int));
sel = 1;
ls = 0;
for(int i = 1; i < n; ++i){
if(sgn(rh[i] - rh[ls]) == dir && (i + 1 == n || sgn(rh[i+1] - rh[i]) == -dir)){
++sel;
ls = i;
dir *= -1;
}
}
selr = max(selr, sel);
// Direction -1
dir = -1;
memset(tx, n, sizeof(int));
sel = 1;
ls = 0;
for(int i = 1; i < n; ++i){
if(sgn(rh[i] - rh[ls]) == dir && (i + 1 == n || sgn(rh[i+1] - rh[i]) == -dir)){
++sel;
ls = i;
dir *= -1;
}
}
selr = max(selr, sel);
cout << selr << endl;
return 0;
}