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 |
几个月前看过,但就是想不明白,今天一见,其实是很简单的题!对砂distance排一下序, 再一次扫描即可!! 因为题目限定的两个条件是一样的,所以只排一次序! 参考: #include <iostream> #include <cstdio> #include <algorithm> using namespace std; const int N = 10010; struct dd { int d, c; } a[N]; int n; bool operator < (const dd & a, const dd & b) { if (a.d != b.d) return a.d < b.d; return a.c < b.c; } int main() { while (scanf("%d", &n), n) { int i; for (i=0; i<n; i++) scanf("%d%d", &a[i].d, &a[i].c); sort(a, a+n); int ans = 0, mi = 1000000; for (i=0; i<n; i++) if (a[i].c < mi) { ans ++; mi = a[i].c; } printf("%d\n", ans); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator