| ||||||||||
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 |
短小In Reply To:终于AC了!内含代码及注释~~ Posted by:shmr0077 at 2011-04-18 14:16:59 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define MAXN 110 #define MAXM 2010 int n, m; int ans[MAXM]; int temp[MAXM]; int row[MAXM]; int main(){ int CASE, i, j, k, x; scanf("%d", &CASE); while(CASE --){ scanf("%d %d", &n, &m); for(i = 0; i < m; ++ i) scanf("%d", &ans[i]); sort(ans, ans + m); for(i = 1; i < n; ++ i){ for(j = 0; j < m; ++ j) scanf("%d", &row[j]); for(j = 0; j < m; ++ j) temp[j] = ans[j] + row[0]; make_heap(temp, temp + m); for(j = 1; j < m; ++ j){ for(k = 0; k < m; ++ k){ x = ans[k] + row[j]; if(x >= temp[0]) break; pop_heap(temp, temp + m); temp[m - 1] = x; push_heap(temp, temp + m); } } sort_heap(temp, temp + m); for(j = 0; j < m; ++ j) ans[j] = temp[j]; } for(j = 0; j < m - 1; ++ j) printf("%d ", ans[j]); printf("%d\n", ans[m - 1]); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator