hdu 4442贪心
挺简单。假设我们现在面对两个要排的队a1, b1和a2, b2,已经花的时间为t,则先排1队需要的时间是a1+a2+t+tb1+tb2+tb1b2+a1b2,而先排2队需要时间是a1+a2+t+tb2+tb1+tb1b2+a2b1,所以实际上只要比较a1b2和a2b1的大小就能确定先排哪个队。按此排个序就行了。
/* * hdu4442/win.cpp * Created on: 2012-10-30 * Author : ben */ #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> #include <iostream> #include <algorithm> #include <queue> #include <set> #include <map> #include <stack> #include <string> #include <vector> #include <deque> #include <list> #include <functional> #include <numeric> #include <cctype> using namespace std; typedef long long LL; const int MOD = 365 * 24 * 60 * 60; inline bool cmp(const pair<int, int> &p1, const pair<int, int> &p2) { LL t1 = (LL)p1.first * p2.second; LL t2 = (LL)p2.first * p1.second; return t1 < t2; } int main() { #ifndef ONLINE_JUDGE freopen("data.in", "r", stdin); #endif int n, a, b; vector<pair<int, int> > que; while(scanf("%d", &n) == 1 && n > 0) { que.clear(); for(int i = 0; i < n; i++) { scanf("%d%d", &a, &b); que.push_back(make_pair(a, b)); } sort(que.begin(), que.end(), cmp); LL ans = 0; for(int i = 0; i < n; i++) { ans += (ans * (que[i].second % MOD) + (que[i].first % MOD)) % MOD; ans %= MOD; } printf("%d\n", (int)(ans % MOD)); } return 0; }