3 条题解

  • 3
    @ 2022-11-16 18:02:45
    #include<bits/stdc++.h>
    using namespace std;
    int a[100005],b[100005];
    int main()
    {
    int n,sum=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
    cin>>a[i];
    if(a[i]>a[i-1])//将输入的数与前一个数作比较
    sum+=a[i]-a[i-1];//最少操作
    }
    cout<<sum;
    return 0;
    }
    
    • 2
      @ 2023-10-20 20:19:55

      代码如下:

      //By:f(x)=Asin(ωx+φ)  ID:142
      
      #include<iostream>
      using namespace std;
      int n,cnt,f,l;
      int main(){ 	
          cin >> n; 	
          for(int i = 0;i < n;i ++){ 		
              cin >> f; 		
              if(f > l)cnt += (f - l); 		
              l = f; 	
          } 	
          cout << cnt; 	
          return 0; 
      }
      

      分析如下:

      WARNING:以下分析内容由 用户 S.H.Z.宋昊哲 (2023songhaozhe) 提供!!!

      举例数据:4 3 2 5 3 5
      数据【4 3 2 5 3 5】可抽象为图示式样:
        432535
      5    ■ ■
      4 ■  ■ ■
      3 ■■ ■■■
      2 ■■■■■■
      1 ■■■■■■
      n=012345 
      
      当 n=0 时,此时未建立任何“■”,∴需要补充建立 4-0=4 个“■”
        4
      5   
      4 ■ ←补充建立 
      3 ■ ←补充建立
      2 ■ ←补充建立
      1 ■ ←补充建立
      n=0,sum = 0+4 = 4 
      
      当 n=1 时,此时已建立 4 个“■”
      ∵4 > 3  ∴不需要补充建立“■”
        43
      5   
      4 ■
      3 ■■
      2 ■■
      1 ■■
      n=01,sum = 4 
      
      当 n=2 时,此时已建立 3 个“■”
      ∵3 > 2  ∴不需要补充建立“■”
        432
      5   
      4 ■
      3 ■■
      2 ■■■
      1 ■■■
      n=012,sum = 4
      
      当 n=3 时,此时已建立 3 个“■”
      ∵2 < 5  ∴需要补充建立 5-2=3 个“■”
        4325
      5    ■ ←补充建立
      4 ■  ■ ←补充建立
      3 ■■ ■ ←补充建立
      2 ■■■■
      1 ■■■■
      n=0123,sum = 4+3 = 7 
      
      当 n=4 时,此时已建立 5 个“■”
      ∵5 > 3  ∴不需要补充建立“■”
        43253
      5     ■
      4 ■   ■
      3 ■■ ■■
      2 ■■■■■
      1 ■■■■■
      n=01234,sum = 7 
      
      当 n=5 时,此时已建立 3 个“■”
      ∵3 < 5  ∴需要补充建立 5-3=2 个“■”
        432535
      5    ■ ■
      4 ■  ■ ■
      3 ■■ ■■■
      2 ■■■■■■
      1 ■■■■■■
      n=012345,sum = 7+2 = 9
      
      综上【数学应用题后遗()()】,sum = 9(输出)
      
    • 0
      @ 2025-3-16 15:53:16

      本题解为@神秘的c++(网名)提供:

      #include<iostream>
      #include<cstdio>
      #include<cstring>
      #include<algorithm>
      #include<cmath>
      using namespace std;
      int n;
      int h,last;
      int sum;
      int main(){
          scanf("%d",&n);
          int i;
          h=last=0;sum=0;
          for(i=1;i<=n;i++){
              scanf("%d",&h);
              if(h>last){
                  sum+=h-last;
              }
              last=h;
          }
          printf("%d\n",sum);
          return 0;
      }
      
      
      • 1

      信息

      ID
      214
      时间
      1000ms
      内存
      256MiB
      难度
      4
      标签
      递交数
      63
      已通过
      31
      上传者