标签:cat seq poj nbsp http sequence ++ sea sum
Time Limit: 6000MS | Memory Limit: 65536K | |
Total Submissions: 9131 | Accepted: 3037 |
Description
Input
Output
Sample Input
1 2 3 1 2 3 2 2 3
Sample Output
3 3 4
Source
1 #include "bits/stdc++.h" 2 #define mem(a,b) memset(a,b,sizeof(a)) 3 #define F(z,x,y) for (z=x;z<=y;z++) 4 using namespace std; 5 typedef long long LL; 6 const int MAX=2005; 7 int cas; 8 int n,m; 9 int s[MAX],sum[MAX]; 10 struct Que{ 11 int h[MAX*100]; 12 int n; 13 Que (){ 14 mem(h,0); 15 n=0; 16 } 17 void heapify(int x){ 18 int child=x*2,key=h[x]; 19 while (child<=n){ 20 if (child<n && h[child]<h[child+1]) child++; 21 if (key<h[child]){h[x]=h[child];x=child,child=x*2;} 22 else break; 23 } 24 h[x]=key; 25 } 26 void insert(int key){ 27 int x=++n; 28 while (x>1){ 29 if (key>h[x/2]) h[x]=h[x/2],x/=2; 30 else break; 31 } 32 h[x]=key; 33 } 34 void del(){ 35 if (n==1) n=0; 36 else h[1]=h[n--],heapify(1); 37 } 38 }; 39 int main(){ 40 freopen ("sequence.in","r",stdin); 41 freopen ("sequence.out","w",stdout); 42 int i,j,k; 43 scanf("%d",&cas); 44 while (cas--){ 45 scanf("%d%d",&n,&m); 46 mem(s,0),mem(sum,0); 47 Que q; 48 F(i,1,m){ 49 scanf("%d",s+i); 50 } 51 F(i,2,n){ 52 F(j,1,m) 53 scanf("%d",sum+j); 54 F(j,1,m) 55 q.insert(sum[1]+s[j]); 56 F(j,2,m) 57 F(k,1,m){ 58 int mx=sum[j]+s[k]; 59 if (mx<q.h[1]){ 60 q.del(); 61 q.insert(mx); 62 } 63 } 64 F(j,1,m) 65 s[j]=q.h[j]; 66 mem(q.h,0); 67 q.n=0; 68 } 69 sort(s+1,s+m+1); 70 F(i,1,m){ 71 printf("%d ",s[i]); 72 } 73 printf("\n"); 74 } 75 return 0; 76 }
标签:cat seq poj nbsp http sequence ++ sea sum
原文地址:http://www.cnblogs.com/keximeiruguo/p/6031462.html