poj 2181 Jumping Cows

poj 2181 Jumping Cows,第1张

poj 2181 Jumping Cows
#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;int n, even, odd;int main(){    scanf("%d", &n);    if (n == 1)    {        int a;        scanf("%d", &a);        printf("%dn", a);        return 0;    }    scanf("%d%d", &odd, &even);    int a, temp;    temp = even;    even = odd - even;    odd = max(temp, odd);    for (int i = 2; i < n; i++)    {        scanf("%d", &a);        temp = max(odd, even + a);        even = max(even, odd - a);        odd = temp;    }    printf("%dn", max(even, odd));    return 0;}

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4925875.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-13
下一篇2022-11-12

发表评论

登录后才能评论

评论列表(0条)

    保存