题解

49 条题解

  • -1
    @ 2015-06-27 12:32:20

    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #define maxn 10020
    using namespace std;
    int a,d;
    int b[maxn];
    int main()
    {scanf("%d",&a);
    for (int i=0;i<a;i++)
    scanf("%d",&b[i]);d=b[0];
    for (int i=1;i<a;i++)
    if (b[i]>=b[i-1]) d=d+b[i]-b[i-1];
    printf("%d\n",d);
    }

  • -1
    @ 2015-06-25 16:44:30

    #include<iostream>
    #include <cstdio>
    #include<cstring>
    #include<cstdlib>
    using namespace std;
    int h[100001]={};
    int main(){
    int n;
    cin>>n;

    for(int i=1;i<=n;i++){
    cin>>h[i];
    }
    h[0]=0;
    int j=0;

    for(int i=1;i<=n;i++){
    if (h[i]>h[i-1]){j+=h[i]-h[i-1];}

    }

    cout<<j;

    }

  • -1
    @ 2015-05-23 14:08:24

    VAR
    ANS,I,J,M,N:LONGINT;
    BEGIN
    READLN(N);
    FOR I:=1 TO N DO
    BEGIN
    READ(J);
    IF J>M THEN ANS:=ANS+J-M;
    M:=J;
    END;
    WRITELN(ANS);
    END.

  • -1
    @ 2015-05-11 20:17:13

    #include <iostream>
    #include <cstdlib>

    using namespace std;

    int a[100005] = {};
    int main(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; ++i){
    cin >> a[i];
    }
    int js = 0;
    for(int i = 1; i <= n; ++i){
    if(a[i] > a[i - 1]){
    js += a[i] - a[i - 1];
    }
    }
    cout << js;
    }

  • -1
    @ 2014-11-01 11:20:02

    ###评测结果
    编译成功

    测试数据 #0: Accepted, time = 15 ms, mem = 476 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 472 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 476 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 472 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 476 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 480 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 476 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 476 KiB, score = 10
    测试数据 #8: Accepted, time = 15 ms, mem = 472 KiB, score = 10
    测试数据 #9: Accepted, time = 31 ms, mem = 476 KiB, score = 10
    Accepted, time = 61 ms, mem = 480 KiB, score = 100
    ###代码
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    #define MAXN 100000+10

    int n,first,next,ans;
    int main() {
    scanf("%d",&n);
    scanf("%d",&first);
    ans = first;
    for(int i = 2; i<=n;i++) {
    scanf("%d",&next);
    if(first<=next) {
    ans+=next-first;
    first = next;
    }else if(first > next) {
    first = next;
    }
    }
    printf("%d",ans);
    return 0;
    }

  • -1
    @ 2014-08-14 19:07:42

    #include<stdio.h>
    int n,i,j,ans=0,min=21000000,w,min2;
    int a[100001]={0};
    int main()
    {
    scanf("%d",&n);
    a[0]=0;
    for(i=1;i<=n;i++)
    scanf("%d",&a[i]);
    for(i=1;i<=n;i++)

    if(a[i]>a[i-1]) ans=ans+(a[i]-a[i-1]);
    printf("%d",ans);
    return 0;
    }

  • -1
    @ 2014-07-13 20:28:41

    #include<cstdio>
    int n,A=0,B,ans=0;
    int main(){
    //freopen("P1844.in","r",stdin);
    //freopen("P1844.out","w",stdout);
    scanf("%d\n",&n);
    for(int i=0;i<n;i++){
    scanf("%d ",&B);
    if(A<B){
    ans+=B-A;
    }else;
    A=B;
    }
    printf("%d\n",ans);
    }
    248KB+77MS

  • -1
    @ 2013-11-23 20:05:57

    var
    a:array[0..100000] of longint;
    n,ans,i,t:longint;
    begin
    readln(n);
    for i:=1 to n do
    read(a[i]);
    ans:=a[1];
    t:=a[1];
    for i:=2 to n do
    begin
    if a[i]>t then ans:=ans+a[i]-t;
    t:=a[i];
    end;
    writeln(ans);
    end.
    水题一道。
    真奇怪竟然是在提高组里出的。
    这适合普及第二道。
    本来还以为我的方法有反例,特地开了个数组,以防不测(可以多扫几遍)。
    后来发现一遍过。
    今天在转C++,发现真的和Pascal有很大的不同。
    好怀念啊。

    • @ 2014-11-06 13:10:13

      这个思路是什么?我看不懂。。。、

  • -2
    @ 2013-11-23 19:52:10

    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 4476 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 4480 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 4476 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 4480 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 4480 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 4480 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 4476 KiB, score = 10
    测试数据 #7: Accepted, time = 31 ms, mem = 4480 KiB, score = 10
    测试数据 #8: Accepted, time = 125 ms, mem = 4480 KiB, score = 10
    测试数据 #9: Accepted, time = 265 ms, mem = 4476 KiB, score = 10
    Accepted, time = 421 ms, mem = 4480 KiB, score = 100

    • @ 2017-11-09 10:15:31

      #1 Accepted 4ms 352.0 KiB
      #2 Accepted 4ms 356.0 KiB
      #3 Accepted 4ms 376.0 KiB
      #4 Accepted 4ms 384.0 KiB
      #5 Accepted 4ms 368.0 KiB
      #6 Accepted 4ms 328.0 KiB
      #7 Accepted 3ms 352.0 KiB
      #8 Accepted 6ms 384.0 KiB
      #9 Accepted 15ms 492.0 KiB
      #10 Accepted 26ms 748.0 KiB

信息

ID
1844
难度
4
分类
(无)
标签
递交数
4002
已通过
1714
通过率
43%
被复制
9
上传者