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 |
ac了,主要是qsort的判定条件写的太简单, 只要加上在len相等情况下处理weight就okIn Reply To:这份代码我在zju上ac了, 可这里判定是wa Posted by:navyakula at 2006-02-03 08:12:04 > 最坏的情况是我在侥幸在zju上过关了,否则, 还会有什么原因呢? > #include <stdio.h> > #include <memory.h> > #include <stdlib.h> > #define MAXN 5001 > struct Stick { > int l, w; > }a[MAXN]; > int n; > int cmp( const void * a, const void * b) > { > return ((const Stick *)a)->l - ((const Stick *)b)->l; > } > int d[MAXN]; > // longest increasing subsequence > int lis() > { > int seg = 0; > int max, sec; > for(int i=1; i<=n; ++i) > { > max = -1; > for(int j=0; j<seg; ++j) if( a[i].w >= d[j] && max < d[j] ) { max = d[j]; sec = j; } > if( max == -1 ) d[seg++] = a[i].w; > else d[sec] = a[i].w; > } > return seg; > } > > int main() > { > int t; scanf("%d", &t); > while( t-- ) > { > scanf("%d", &n); > for(int i=1; i<=n; ++i) scanf("%d%d", &a[i].l, &a[i].w); > qsort( &a[1], n, sizeof(Stick), cmp ); > printf( "%d\n", lis() ); > } > return 0; > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator