Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:神奇的 WA ,求大神解答In Reply To:神奇的 WA ,求大神解答 Posted by:wangheda at 2016-08-24 17:13:50 > 本地 G++ 全部正确,在线 G++ 编译 WA, C++ 编译 AC,代码如下: > > #include<iostream> > #include<iomanip> > #include<cmath> > using std::ios; using std::cout; using std::cin; using std::cerr; using std::endl; > using std::fixed; using std::setprecision; > > #define REP1(i,n) for(int i=1, _##i=(n+1); i<_##i; ++i) > #define REP(i,n) for(int i=0, _##i=(n); i<_##i; ++i) > #define INIT(a,b) memset(a,b,sizeof(a)) > #define MAX(a,b) ((a)>(b)?(a):(b)) > #define MIN(a,b) ((a)<(b)?(a):(b)) > #define PI 3.1415926535898 > #define INF 1000000000 > > int sum[600][60]; > int village[600]; > > int main() { > std::ios::sync_with_stdio(false); > > REP(i,600) REP(j,60) sum[i][j] = INF; > > int V,P; cin >> V >> P; > REP1(v,V) cin >> village[v]; > > int s = 0; > // base > REP1(v,V) { > s += village[v]; > sum[v][1] = v * village[v] - s; > } > > for (int p=1; p <= P-1; p++) { > for (int v1=p; v1 <= V; v1++) { > int k = v1, v2 = v1+1; > int s1 = village[v1], s2 = village[v1]; > while (v2 <= V) { > if (village[v2] - village[k+1] <= village[k+1] - village[v1]) { > s2 += village[v2]; > sum[v2][p+1] = MIN(sum[v2][p+1], sum[v1][p] + (s1 - (k-v1+1)*village[v1]) + ((v2-k)*village[v2] - (s2-s1))); > v2 ++; > } else { > k ++; > s1 += village[k]; > } > } > } > > // REP1(i,P) { > // REP1(j, V) cout << sum[j][i] << ' '; cout << endl; > // } > // cout << endl; > } > > int min = INF; > s = 0; > for (int v=V; v>0; v--) { > s += village[v]; > min = MIN(min, sum[v][P] + s - (V-v+1)*village[v]); > } > cout << min << endl; > return 0; > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator