zoukankan      html  css  js  c++  java
  • hdu 5280 Senior's Array

    题目连接

    http://acm.hdu.edu.cn/showproblem.php?pid=5280    

    Senior's Array

    Description

    One day, Xuejiejie gets an array $A$. Among all non-empty intervals of $A$, she wants to find the most beautiful one. She defines the beauty as the sum of the interval. The beauty of the interval---$[L,R]$ is calculated by this formula : beauty$(L,R) = A[L]+A[L+1]+……+A[R]$. The most beautiful interval is the one with maximum beauty.

    But as is known to all, Xuejiejie is used to pursuing perfection. She wants to get a more beautiful interval. So she asks Mini-Sun for help. Mini-Sun is a magician, but he is busy reviewing calculus. So he tells Xuejiejie that he can just help her change one value of the element of $A$ to $P$ . Xuejiejie plans to come to see him in tomorrow morning.

    Unluckily, Xuejiejie oversleeps. Now up to you to help her make the decision which one should be changed(You must change one element).

    Input

    In the first line there is an integer $T$, indicates the number of test cases.

    In each case, the first line contains two integers $n$ and $P$. $n$ means the number of elements of the array. $P$ means the value Mini-Sun can change to.

    The next line contains the original array.

    $1leq nleq 1000$, $-10^9leq A[i], Pleq 10^9$。

    Output

    For each test case, output one integer which means the most beautiful interval's beauty after your change.

    2
    3 5
    1 -1 2
    3 -2
    1 -1 2

    Sample Output

    8
    2

    数据才1000直接暴力。。

     1 #include<algorithm>
     2 #include<iostream>
     3 #include<cstdlib>
     4 #include<cstring>
     5 #include<cstdio>
     6 #include<vector>
     7 #include<map>
     8 using std::max;
     9 using std::cin;
    10 using std::cout;
    11 using std::endl;
    12 using std::find;
    13 using std::sort;
    14 using std::map;
    15 using std::pair;
    16 using std::vector;
    17 using std::multimap;
    18 #define pb(e) push_back(e)
    19 #define sz(c) (int)(c).size()
    20 #define mp(a, b) make_pair(a, b)
    21 #define all(c) (c).begin(), (c).end()
    22 #define iter(c) decltype((c).begin())
    23 #define cls(arr,val) memset(arr,val,sizeof(arr))
    24 #define cpresent(c, e) (find(all(c), (e)) != (c).end())
    25 #define rep(i, n) for (int i = 1; i <= (int)(n); i++)
    26 #define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
    27 const int N = 1010;
    28 const int INF = 0x7fffffff;
    29 typedef long long ll;
    30 ll p, ans, arr[N], sum[N];
    31 int main() {
    32 #ifdef LOCAL
    33     freopen("in.txt", "r", stdin);
    34     freopen("out.txt", "w+", stdout);
    35 #endif
    36     int t, n;
    37     scanf("%d", &t);
    38     while (t--) {
    39         ans =  -INF;
    40         scanf("%d %lld", &n, &p);
    41         rep(i, n) scanf("%lld", &arr[i]);
    42         rep(i, n) {
    43             ll tmp = arr[i]; arr[i] = p;
    44             rep(j, n) {
    45                 sum[j] = sum[j - 1] > 0 ? sum[j - 1] + arr[j] : arr[j];
    46                 ans = max(ans, sum[j]);
    47             }
    48             arr[i] = tmp;
    49         }
    50         printf("%lld
    ", ans);
    51     }
    52     return 0;
    53 }
    View Code
    By: GadyPu 博客地址:http://www.cnblogs.com/GadyPu/ 转载请说明
  • 相关阅读:
    centos7安装mysql8 ERROR! The server quit without updating PID file
    linux桌面系统开启windows远程访问
    intellij ide 激活(转发)
    intellij ide调用一个对象所有的set方法
    linux服务器磁盘挂载
    互联网公司研发团队服务器开发工具清单
    intellij ide 集成cmder
    maven 私服上有jar包但是却下载不下来
    java开发人员win10配置
    996 icu我能为你做什么?
  • 原文地址:https://www.cnblogs.com/GadyPu/p/4641675.html
Copyright © 2011-2022 走看看