-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathislands.cpp
74 lines (65 loc) · 1.73 KB
/
islands.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <unordered_map>
#define EPSILON 0.00001
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll i, j, k;
ll bound;
ll islands = 0;
ll garb;
ll cases;
ll temp, temp2;
ll left, right;
cin >> cases;
for(i = 0; i < cases; i++)
{
vector<ll> sequence (12);
islands = 0;
cin >> garb;
for(j = 0; j < 12; j++)
{
cin >> sequence[j];
}
for(j = 1; j < 11; j++)
{
for(k = 10; k >= 0; k--)
{
if ((j + k) < 11)
{
temp = *(max_element(sequence.begin()+j, sequence.begin() + j + k + 1));
temp2 = *(min_element(sequence.begin()+j, sequence.begin() + j + k + 1));
left = sequence[j-1];
right = sequence[j + k + 1];
if (temp > left && temp > right && temp2 > left && temp2 > right )
{
islands++;
//cout << "range: " << j << "->" << j + k << " " << temp << " " << temp2 << "\n";
//cout << "left: " << left << " " << "right: " << right << "\n";
}
}
}
}
cout << garb << " " << islands << "\n";
}
return 0;
}