//连续的和的绝对值最小 # include <stdio.h> # include <string.h> # include <algorithm> # include <math.h> using namespace std; int main() { int t,i,j,num,n,min1; int sum[1010],a[1010]; int cas=0; while(~scanf("%d",&t)) { while(t--) { scanf("%d",&n); for(i=0; i<n; i++) scanf("%d",&a[i]); min1=999999999; for(i=0; i<n; i++) { sum[i]=abs(a[i]); num=a[i]; for(j=i-1; j>=0; j--) { num=num+a[j]; if(sum[i]>abs(num)) sum[i]=abs(num); } if(min1>sum[i]) min1=sum[i]; } printf("Case %d: %d\n",++cas,min1); } } return 0; }
时间: 2024-10-10 14:19:52