标签:
Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1057 Accepted Submission(s): 354
int a = Lsize - i; 表示的是什么呢?表示从左半圆选择i个 那么剩下的部分不跨圆,继续使用拿完原路返回策略
int b = max(0,Rsize - (K - i)); 剩下的 K- i个采用拿了原路返回的策略
ret = min(ret,((sum[a][0] + sum[b][1])<<1) + Len); 那么这K个,我们采用拿了 不原路返回,采用绕圆的方法
所以多了Len
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long LL; 4 const int maxn = 100010; 5 LL d[maxn],tot,sum[maxn][2]; 6 vector<LL>L,R; 7 int main() { 8 int kase,n,K,m,pos; 9 LL Len; 10 scanf("%d",&kase); 11 while(kase--) { 12 scanf("%d%d%d",&pos,&n,&K); 13 L.clear(); 14 R.clear(); 15 Len = pos; 16 for(int i = tot = 0; i < n; ++i) { 17 scanf("%d%d",&pos,&m); 18 for(int j = 0; j < m; ++j) 19 d[tot++] = pos; 20 } 21 for(int i = 0; i < tot; ++i) { 22 if(d[i]*2 < Len) L.push_back(d[i]); 23 else R.push_back(Len - d[i]); 24 } 25 sort(L.begin(),L.end()); 26 sort(R.begin(),R.end()); 27 int Lsize = L.size(),Rsize = R.size(); 28 sum[0][0] = sum[0][1] = 0; 29 for(int i = 0; i < Lsize; ++i) 30 if(i + 1 <= K) sum[i + 1][0] = L[i]; 31 else sum[i + 1][0] = sum[i - K + 1][0] + L[i]; 32 for(int i = 0; i < Rsize; ++i) 33 if(i + 1 <= K) sum[i+1][1] = R[i]; 34 else sum[i+1][1] = sum[i-K+1][1] + R[i]; 35 LL ret = (sum[Lsize][0] + sum[Rsize][1])<<1; 36 for(int i = 0; i <= Lsize && i <= K; ++i) { 37 int a = Lsize - i; 38 int b = max(0,Rsize - (K - i)); 39 ret = min(ret,((sum[a][0] + sum[b][1])<<1) + Len); 40 } 41 cout<<ret<<endl; 42 } 43 return 0; 44 }
2015 Multi-University Training Contest 2 hdu 5303 Delicious Apples
标签:
原文地址:http://www.cnblogs.com/crackpotisback/p/4676293.html