2016-06-24 解題區/解題區 - UVa UVa 13070 - Palm trees in the snow contents 1. Problem2. Sample Input3. Sample Output4. Solution Problem給一排棕梠樹的樹高 $H_i$,經過大雪後,高度 $H_i \ge W$ 的樹都會攤倒,挑選一個區間滿足最多五棵屹立不搖的情況下,請問區間長度最長為何? Sample Input123456789103301010 30 50 20 40 60 30 40 50 36401010 30 50 20 40 20 10 10 20 3620340 10 15 Sample Output1237103 Solution將會倒的位置記錄下來,線性掃描過去即可。 123456789101112131415161718192021222324252627#include <bits/stdc++.h>using namespace std;int main() { int testcase; scanf("%d", &testcase); while (testcase--) { int W, N, x; scanf("%d %d", &W, &N); vector<int> A; A.push_back(-1); for (int i = 0; i < N; i++) { scanf("%d", &x); if (x >= W) A.push_back(i); } A.push_back(N); int ret = 0; for (int i = 1; i < A.size()-1; i++) { int x = A[min(i+5, (int)A.size()-1)]; ret = max(ret, x - A[i-1]-1); } if (A.size() == 2) ret = N; printf("%d\n", ret); } return 0;} Newer UVa 13000 - VIP Treatment Older UVa 13036 - Birthday Gift to SJ - 2