hdu 4223

暴力:

Problem :  ( Dynamic Programming? )     Judge Status : Accepted
RunId : 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[][];
int b[];
int main()
{
int t,n;
int i,j,k;
scanf("%d",&t);
int _case=;
while(t--)
{
scanf("%d",&n);
for(i=;i<n;i++)
scanf("%d",&b[i]);
int Min=INF;
//for()
for(i=;i<n;i++)
{
a[i][i]=b[i];
Min=min(abs(a[i][i]),abs(Min));
for(j=i+;j<n;j++)
{
a[i][j]=a[i][j-]+b[j];
Min=min(abs(a[i][j]),abs(Min));
}
}
printf("Case %d: %d\n",++_case,abs(Min));
}
}

预处理:

Problem :  ( Dynamic Programming? )     Judge Status : Accepted
RunId : 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[];
int a[];
int main()
{
int i,j,k,n,kk=,t;
cin>>t;
while(t--)
{
cin>>n;kk++;
memset(s,,sizeof(s));
for(i = ; i <= n ; i++)
{
scanf("%d",&a[i]);
s[i] = s[i-]+a[i];
}
int minz=INF;
for(i = ; i <= n ; i++)
for(j = ; j < i ; j++)
{
int x = abs(s[i]-s[j]);
minz = min(minz,x);
}
printf("Case %d: ",kk);
cout<<minz<<endl;
}
return ;
}
上一篇:升级项目到.NET Core 2.0,在Linux上安装Docker,并成功部署


下一篇:wifidog源码分析 - 用户连接过程