JZOJ 3832. 在哪里建酿酒厂
题目
分析
- 暴力,前缀和求长度即可
代码
1 #include <cmath> 2 #include <cstdio> 3 #include <cstring> 4 #include <iostream> 5 #include <algorithm> 6 #define ll long long 7 using namespace std; 8 ll sum1[10010],sum2[10010],a[10010],w[10010]; 9 int main() 10 { 11 freopen("bro.in","r",stdin); 12 freopen("bro.out","w",stdout); 13 ll n,sum=0; 14 scanf("%lld",&n); 15 for (int i=1;i<=n;i++) scanf("%lld%lld",&a[i],&w[i]),sum+=w[i]; 16 for (int i=1;i<=n;i++) sum1[i]=sum1[i-1]+w[i]; 17 ll ans=1e16,h; 18 for (int i=1;i<=n;i++) 19 { 20 h=0; 21 for (int j=1;j<=n;j++) 22 { 23 if (h>=ans) break; 24 if (i==j) continue; 25 h+=a[j]*min(abs(sum1[i-1]-sum1[j-1]),sum-abs(sum1[i-1]-sum1[j-1])); 26 } 27 ans=min(ans,h); 28 } 29 cout<<ans; 30 return 0; 31 }
为何要逼自己长大,去闯不该闯的荒唐