这题我自己卡在题目的定义无法掌握(题目中bad的定义),突破点在於看到了题目中的范例测试资料,假如没有题目的范例测试资料了话,就需要想像更多的可能情况,才可以好好理解定义的意义为何
// https://codeforces.com/contest/1550/problem/C
#include <iostream>
using namespace std;
bool is_good(long long a, long long b, long long c)
{
return (b - a) * (b - c) > 0;
}
int main()
{
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n];
int count = 0;
for (int i = 0; i < n; i++)
cin >> a[i];
count += 2 * n - 1;
for (int i = 0; i < n-2; i++)
if (is_good(a[i], a[i+1], a[i+2]))
count++;
for (int i = 0; i < n-3; i++)
if (is_good(a[i], a[i+1], a[i+2]) && is_good(a[i+1], a[i+2], a[i+3]) &&
is_good(a[i], a[i+1], a[i+3]) && is_good(a[i], a[i+2], a[i+3]))
count++;
cout << count << endl;
}
return 0;
}
<<: Outstanding ecommerce website design
还记得在中坜上课时,吴老师常说:Java因介面而伟大。 初学物件导向程序概念,还真的不太能体悟为什麽...
延续昨天,我们来看可以怎麽在 Laravel 框架下实作签证的验证。 What is middlew...
今天来看 RISC-V 系列的最後一篇文件,Supporting PMUs on RISC-V pl...
请问各位大大,小的想去考111年的半导体布局设计工程师能力监定,请问哪里可以有实体或线上课程呢,上完...
终於要开始了:「说到底,单元测试怎麽做?」 单元测试 单元测试要测的是一个逻辑单元功能是否正确。这短...