uva 11078

/**
 * @brief uva 11078
 * @file 11078
 * @author mianma
 * @created 2014/12/23 16:40
 * @edited  2014/12/23 16:40
 * @type 
 * @note
 */

#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <cassert>

using namespace std;

#define max(a, b)  ((a) > (b) ? (a) : (b))
#define min(a, b)  ((a) > (b) ? (b) : (a)) 
#define abs(a)     ((a) >  0  ? (a) : (0 - (a)))
#define CLR(vec)   memset(vec, 0, sizeof(vec))

#define MAXN 100000
#define MAXV 150000

int T, n;
int record[MAXN + 10];
int table[MAXN + 10];

/*fast read IO*/
int read_int(){
    int neg = 0;
    int ch = getchar();
    while(!isdigit(ch) && ‘-‘ != ch)
        ch = getchar();
    if(‘-‘ == ch){
        ch = getchar();
        neg = 1;
    }
    int x = 0;
    while(isdigit(ch)){
        x  = x*10 + ch - ‘0‘;
        ch = getchar();
    }
    return ( neg ? 0 - x : x );
}

/*fast write IO*/
int write_int(int x){
    int neg = 0;
    static char buf[MAXV + 10];
    int n = 0;
    if(x < 0){
        neg = 1;
        x = abs(x);
    }
    while(x){
        buf[n++] = x%10 + ‘0‘;
        x       /= 10;
    }
    if(neg)
        putchar(‘-‘);
    for(int i = n -1 ; i >= 0; i--)
        putchar(buf[i]);
}

int main(void){
    int maxval, tmp;
#ifdef DEBUG
    freopen("./in", "r", stdin);
    freopen("./out", "w", stdout);
#endif
    scanf("%d", &T);
    while(T--){
        scanf("%d", &n);
        maxval = -MAXV - 10;
        for(int i = 1; i <= n; i++){
                record[i] = maxval;
                table[i] = read_int();
                maxval = max(maxval, table[i]);
        }
        maxval = -MAXV - 10;
        for(int i = 2; i <= n; i++)
                maxval = max(maxval, record[i] - table[i]);
        write_int(maxval);
        putchar(‘\n‘);
    }
    return 0;
}
时间: 2024-08-29 04:53:54

uva 11078的相关文章

[2016-03-19][UVA][11078][Open Credit System]

时间:2016-03-19 20:58:13 星期六 题目编号:[2016-03-19][UVA][11078][Open Credit System] 题目大意:求一个序列中 Ai - Aj的最大值(i < j) 分析:维护j前面最大的Ai ,更新ans即可 #include <cstdio> #include<algorithm> using namespace std; #define FOR(x,y,z) for(int (x)=(y);(x)<(z);++(x

UVA - 11078 - Open Credit System (高效算法的应用!!)

UVA - 11078 Open Credit System Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description Problem E Open Credit System Input: Standard Input Output: Standard Output In an open credit system, the students can choos

Uva 11078 简单dp

题目链接:http://uva.onlinejudge.org/external/110/11078.pdf a[i] - a[j] 的最大值. 这个题目马毅问了我,O(n^2)超时,记忆化一下当前最大值. 1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 int A[100000],n; 6 7 int main() 8 { 9 int t; 10 cin>>t; 11 while(t--) { 12 cin>&

UVA之11078 - Open Credit System

[题目] Problem E Open Credit System Input: Standard Input Output: Standard Output In an open credit system, the students can choose any course they like, but there is a problem. Some of the students are more senior than other students. The professor of

11078 - Open Credit System

11078 - Open Credit System Time limit: 3.000 seconds Problem E Open Credit System Input: Standard Input Output: Standard Output In an open credit system, the students can choose any course they like, but there is a problem. Some of the students are m

UVA 562 Dividing coins --01背包的变形

01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 50007 int c[102],d

UVA 10341 Solve It

Problem F Solve It Input: standard input Output: standard output Time Limit: 1 second Memory Limit: 32 MB Solve the equation: p*e-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x2 + u = 0 where 0 <= x <= 1. Input Input consists of multiple test cases and te

UVA 11014 - Make a Crystal(容斥原理)

UVA 11014 - Make a Crystal 题目链接 题意:给定一个NxNxN的正方体,求出最多能选几个整数点.使得随意两点PQ不会使PQO共线. 思路:利用容斥原理,设f(k)为点(x, y, z)三点都为k的倍数的点的个数(要扣掉一个原点O).那么全部点就是f(1),之后要去除掉共线的,就是扣掉f(2), f(3), f(5)..f(n).n为素数.由于这些素数中包括了合数的情况,而且这些点必定与f(1)除去这些点以外的点共线,所以扣掉.可是扣掉后会扣掉一些反复的.比方f(6)在f

[UVa] Palindromes(401)

UVA - 401 Palindromes Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDED