1 solutions
-
0
P1150 The wonderful adventure of night —— Scaling Heights 题解
题意分析:
我觉得解决本题的思路题目上写的很清楚了,就差具体代码的实现。无非是根据要求走一遍二维数组,用一个sum记录下走过的点位的分数。有一个坑点需要注意,就是走过的分数最高的点位可以获得双倍的分数,但是这个点位可能有很多个,所以需要开一个数组将每个走过的点位存进去,在结束前进后遍历一遍这个数组找到最大值即分数最高的点位,然后再遍历一遍数组,将每一个最大值都再加入一遍到sum中。
参考代码:
#include <bits/stdc++.h> using namespace std; int f[102][102]; int temp[101]; int main() { int T; cin >> T; while (T--) { memset(f,0,sizeof(f)); memset(temp,0,sizeof(temp)); int n,t = 0; cin >> n; int sum = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { cin >> f[i][j]; } } int i = n; int j = 1; while (f[i][j] != 0) { temp[++t] = f[i][j]; sum += f[i][j]; if (f[i - 1][j + 1] > f[i][j]) { i = i - 1; j = j + 1; continue; } if (f[i][j + 1] == f[i][j]) { j = j + 1; continue; } if (f[i + 1][j + 1] < f[i][j]) { i = i + 1; j = j + 1; continue; } break; } int max = temp[1]; for (int i = 2; i <= n; i++) { if (temp[i] > max) max = temp[i]; } for (int i = 1; i <= n; i++) { if (temp[i] == max) sum += temp[i]; } cout << sum << endl; } }
- 1
Information
- ID
- 146
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 8
- Tags
- # Submissions
- 117
- Accepted
- 14
- Uploaded By