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 |
崩溃了,怎么可能WA呢,摆脱牛人帮我看看啊,谢谢了(附代码)#include <iostream> #include <algorithm> #include <cstdio> #include <queue> #define MAX 5005 using namespace std; class woodclass { public: int l; int w; woodclass() { l = 0; w = 0; } }wood[MAX], fir, sec; bool cmp1(woodclass a, woodclass b); bool cmp2(woodclass a, woodclass b); int result(bool (*cmp)(woodclass a, woodclass b), int n, int cnt); int main() { int t; int n; int i, j; int cnt; int r1, r2; scanf("%d", &t); for(j=0; j<t; j++) { cnt = 1; scanf("%d", &n); if(n == 0) { printf("0\n"); continue; } for(i=0; i<n; ++i) { scanf("%d %d", &wood[i].l, &wood[i].w); } r1 = result(cmp1, n, cnt); r2 = result(cmp2, n, cnt); if(r2 < r1) { printf("%d\n", r2); } else { printf("%d\n", r1); } } return 0; } bool cmp1(woodclass a, woodclass b) { if(a.l == b.l) return a.w < b.w; return (a.l < b.l); } bool cmp2(woodclass a, woodclass b) { if(a.w == b.w) return a.l < b.l; return (a.w < b.w); } int result(bool (*cmp)(woodclass a, woodclass b), int n, int cnt) { int i; int time = n - 1; sort(wood, wood + n, cmp); queue<woodclass> a; for(i=0; i<n; ++i) { a.push(wood[i]); } while(time--) { fir = a.front(); a.pop(); sec = a.front(); if (fir.l > sec.l || fir.w > sec.w) { cnt++; } } return cnt; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator