HDOJ1002 A+B Problem II

HDOJ1002 A+B Problem IIWrong Answer.代码如下:

#include<iostream>

using namespace std;

int main()
{
    int n;
    while(cin>>n &&n)
    {
        int *a = new int[n];
        int sumRun=0,sumStop=0,sumTotal=0;
        int i=0;
        a[0]=0;
        for (i=1;i<=n;i++)
        {
            cin>>a[i];
            if (a[i]>a[i-1]) {
                sumRun = sumRun + ((a[i]-a[i-1])*6);
            }
            else if (a[i]<a[i-1]){
                sumRun = sumRun + ((a[i-1]-a[i])*4);
            }
            else{
                sumRun = sumRun + 0;
            }
        }
        sumStop = n*5;
        sumTotal = sumRun + sumStop;
        cout<<sumTotal<<endl;
    }
    return 0;
}
时间: 2024-10-12 15:35:19

HDOJ1002 A+B Problem II的相关文章

HDOJ-1002 A + B Problem II (非负大整数相加)

http://acm.hdu.edu.cn/showproblem.php?pid=1002 输入的数都是正整数,比较好处理,注意进位. //非负大整数加法 # include <stdio.h> # include <string.h> # define MAX 1100 int main() { int t; char Num1[MAX], Num2[MAX], Num3[MAX];//Num3[] 用于保存结果 scanf("%d", &t); f

杭电1023Train Problem II

地址:http://acm.hdu.edu.cn/showproblem.php?pid=1023 题目: Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7675    Accepted Submission(s): 4131 Problem Description As we all know the

Train Problem II 卡特兰裸题(入门题)

Train Problem II  题目大意:给你一个数n,表示有n辆火车,编号从1到n,从远方驶过来,问你有多少种出站的可能. 解题思路:模拟栈的问题而已.  卡特兰问题. 1 import java.math.*; 2 import java.util.*; 3 import java.io.*; 4 5 public class Main 6 { 7 static int MS=101; 8 public static void main(String[] args) 9 { 10 Sca

hdoj 1002 A + B Problem II

A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 242959    Accepted Submission(s): 46863 Problem Description I have a very simple problem for you. Given two integers A and B, you

【HDOJ 1002】A + B Problem II

A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 238517    Accepted Submission(s): 45969 Problem Description I have a very simple problem for you. Given two integers A and B, you

HDU 1002-A + B Problem II(大数类)

A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 215173    Accepted Submission(s): 41521 Problem Description I have a very simple problem for you. Given two integers A and B, yo

hdoj 1023 Train Problem II 【卡特兰】+【高精度】

题意:询问有多少种进站出站的顺序. 经典卡特兰.我对卡特兰目前的认识就是有n个1和n个-1,组成一个为2n的数列的方式有多少种.这就跟火车进站出站类似, 至于具体的卡特兰数的介绍,百度解释的很详细. 代码1(c语言): /* h(n) = h(n-1)*(4*n-2)/(n+1); */ #include <stdio.h> #include <string.h> #define M 110 int s[M][M] = {0}, b[M]; void init(){ s[1][0]

A + B Problem II(杭电1002)

/*A + B Problem II Problem Description I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B. Input The first line of the input contains an integer T(1<=T<=20) which means the number of test case

HDU 1002 A + B Problem II(大整数相加)

A + B Problem II Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B. Input The first line of the input c