• hdu 4223


    暴力:

    Problem : 4223 ( Dynamic Programming? )     Judge Status : Accepted
    RunId : 9293515    Language : C++    Author : yudunfengqing
    Code Render Status : Rendered By HDOJ C++ Code Render Version 0.01 Beta
    #include<stdio.h>
    #include<math.h>
    #include<algorithm>
    using namespace std;
    #define INF 0xfffffff
    int a[1010][1010];
    int b[1010];
    int main()
    {
        int t,n;
        int i,j,k;
        scanf("%d",&t);
        int _case=0;
        while(t--)
        {
            scanf("%d",&n);
            for(i=0;i<n;i++)
                scanf("%d",&b[i]);
            int Min=INF;
            //for()
            for(i=0;i<n;i++)
            {
                a[i][i]=b[i];
                Min=min(abs(a[i][i]),abs(Min));
                for(j=i+1;j<n;j++)
                {
                    a[i][j]=a[i][j-1]+b[j];
                    Min=min(abs(a[i][j]),abs(Min));
                }
            }
            printf("Case %d: %d
    ",++_case,abs(Min));
        }
    }

    预处理:

    Problem : 4223 ( Dynamic Programming? )     Judge Status : Accepted
    RunId : 9293542    Language : C++    Author : yudunfengqing
    Code Render Status : Rendered By HDOJ C++ Code Render Version 0.01 Beta
    #include <iostream>
     #include<cstdio>
     #include<cstring>
     #include<algorithm>
     #include<stdlib.h>
     #include<cmath>
     using namespace std;
     #define LL __int64
     #define INF 0xfffffff
     int s[1010];
     int a[1010];
     int main()
     {
         int i,j,k,n,kk=0,t;
         cin>>t;
         while(t--)
         {
             cin>>n;kk++;
             memset(s,0,sizeof(s));
             for(i = 1; i <= n ; i++)
             {
                 scanf("%d",&a[i]);
                 s[i] = s[i-1]+a[i];
             }
             int minz=INF;
             for(i = 1; i <= n ; i++)
                 for(j = 0; j < i ; j++)
                 {
                     int x = abs(s[i]-s[j]);
                     minz = min(minz,x);
                 }
             printf("Case %d: ",kk);
             cout<<minz<<endl;
         }
         return 0;
     }
    View Code
  • 相关阅读:
    Lua函数
    Lua 造成的代码冗余太严重了, 这个现状怎么改善?
    Lua 造成的代码冗余太严重了, 这个现状怎么改善?
    Lua 错误处理方法
    Lua 错误处理方法
    C++引用、指针的选择
    C++引用、指针的选择
    Windows 7下VS2008升级补丁
    Windows 7下VS2008升级补丁
    天龙八部服务器端共享内存的设计(3/3)
  • 原文地址:https://www.cnblogs.com/XDJjy/p/3355562.html
Copyright © 2020-2023  润新知