zoukankan      html  css  js  c++  java
  • UVa11078:Open Credit System

    UVa11078:Open Credit System


    题目大意


    给定一个数组A,求Ai-Aj的最大值(i<j)

    要求复杂度:Ο(n)

    Solution


    对给定的j,为了Ai-Aj取得最大值,Ai应该取最大,因此可以用一个变量maxA维护最大值,边读边计算答案。

    AC-Code(C++)


    Time:50ms

    #include <iostream>
    #include <iomanip>
    #include <algorithm>
    #include <string>
    #include <cstring>
    #include <map>
    #include <set>
    #include <vector>
    #include <cmath>
    #include <climits>
    #include <ctime>
    
    using namespace std;
    typedef long long ll;
    const int INF = 0x3f3f3f3f;
    const double PI = acos(-1.0);
    const int maxn = 30000 + 10;
    
    int main(int argc, const char * argv[]) {
        
    //    freopen("input.txt", "r", stdin);
        
        int n,T;
        scanf("%d",&T);
        while(T--){
            scanf("%d",&n);
            int maxA;
            scanf("%d",&maxA);
            int ans = -INF;
            int temp;
            for(int i=1;i<n;i++){
                scanf("%d",&temp);
                ans = max(ans,maxA-temp);
                maxA = max(maxA,temp);
            }
            
            printf("%d
    ",ans);
        }
        return 0;
    }
    
  • 相关阅读:
    Create方法失效而没有提示错误信息
    JS弹出窗口控制
    本周活动
    JavaScript的初步了解
    关于PHP接收文件的资料
    mvc模式改进网站结构
    一周动态
    排序
    Java的内存泄漏
    Android笔记
  • 原文地址:https://www.cnblogs.com/irran/p/UVa11078.html
Copyright © 2011-2022 走看看