URAL 1011 Conductors

[报告]

   数学问题……(不过我不知道我以前的程序为什么错)

   先将P,Q从百分数换成小数,然后枚举汽车的数量,直到区间[I/Q,I/P]之间有正整数(这个判断影响程序的正确性和效率),答案就是I/Q,I/P]之间最小正整数。

[程序]

#include <cstdlib>
#include <iostream>
#include <cmath>
#define d 1e-6
using namespace std;

int main(int argc, char *argv[])
{
    double p,q;
    cin >> p >> q;
    p=p/100;q=q/100;
    for (long i=1;true;i++)
    {
        double x=i/p,y=i/q;
      //  cout << x << " " << y << endl;
        if (long(y+d)+1<=long(x-d))
        {
           cout << long(y+d)+1 << endl;
           break;
        }
   //     cin.get();
    }
  //  system("PAUSE");
    return EXIT_SUCCESS;
}

posted @ 2009-12-04 13:54  为美好世界献上珂学  阅读(87)  评论(0)    收藏  举报