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 |
Re:Johnson算法模板题In Reply To:Johnson算法模板题 Posted by:buaabarty at 2012-07-26 11:53:42 > 一水 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; struct data { int x, y; bool operator < (const data a) const { if (x < y) return ((a.x >= a.y) || (x < a.x)); else return ((a.x >= a.y) && (y > a.y)); } }a[10010]; int main() { int n; while (scanf("%d", &n), n) { for (int i = 1; i <= n; ++i) { int x, y; scanf("%d%d", &a[i].x, &a[i].y); } sort(a+1, a+n+1); int t1 = 0, t2 = 0; for (int i = 1; i <= n; ++i) { t1 += a[i].x; t2 = max(t1, t2) + a[i].y; } printf("%d\n", t2); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator