1 条题解
-
0
C++ :
#include<bits/stdc++.h> using namespace std; int main() { //r:生成数,a:高度数组 int n, r[110],a[110]; cin >> n >> r[1]; a[1] = r[1] % 10; for (int i = 2; i <= n; i++) { r[i] = (r[i - 1] * 6807 + 2831) % 201701; a[i] = r[i] % 10; } int left[110], right[110]; left[1] = a[1], right[n] = a[n];//初始化 //扫一遍左边高的 for (int i = 2; i <= n; i++) { left[i] = max(left[i - 1], a[i]); } //扫一遍右边高的 for (int i = n - 1; i > 0; i--) { right[i] = max(right[i + 1], a[i]); } // for(int i = 1;i <= n;i++){ // cout<<a[i]<<" "<<left[i]<<" "<<right[i]<<endl; // } int cnt = 0; for (int i = 2; i <= n; i++) { cnt += min(left[i], right[i]) - a[i]; } cout << cnt << "\n"; return 0; }
- 1
信息
- ID
- 2466
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者