百度之星程序设计大赛 J题 电梯不能停在0层,这我WA了好几次,泪崩!

View Code
 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 
 4 long min = 99999999; 
 5 int main()
 6 {
 7      int i,a,b,m;
 8      long n,sum,x;
 9       
10      scanf("%ld%d",&n,&m); 
11      sum = -1; 
12      for(i=0; i<m; i++)
13      {
14         scanf("%d%d",&a,&b); 
15         x = (n*b)/(a+b) + 1; 
16          sum = (a+b)*x - n*b;    
17         if(min > sum)          
18            min = sum; 
19      }   
20      printf("%d\n",min);
21    return 0; 
22 } 
posted @ 2012-05-31 19:30  zhongya  阅读(137)  评论(0编辑  收藏  举报