对于两组数据 x1 y1和x2 y2根据题目可以得出如果第一组数据排在第二组数据前面,那么x1*y2<x2*y1。所以只要排下序就可以了。

代码:

 

 1  #include <algorithm>
 2  #include <iostream>
 3  #include <cstring>
 4  #include <cstdio>
 5  #define LL long long
 6  using namespace std;
 7  struct node
 8  {
 9      LL x;
10      LL y;
11  }p[100010];
12  const LL mod=365*24*60*60;
13  bool comp(struct node a,struct node b)
14  {
15      return a.x*b.y<b.x*a.y;
16  }
17  int main()
18  {
19      int n;
20      while(~scanf("%d",&n))
21      {
22          LL s=0;
23          if(!n)
24              break;
25          for(int i=0;i<n;i++)
26          {
27              scanf("%lld%lld",&p[i].x,&p[i].y);
28          }
29          sort(p,p+n,comp);
30          for(int i=0;i<n;i++)
31          {
32              s=(s+s*p[i].y+p[i].x)%mod;
33          }
34          printf("%lld\n",s);
35      }
36      return 0;
37  }

 

 

 

posted on 2012-10-29 22:04  pony1993  阅读(482)  评论(0编辑  收藏  举报

View My Stats