Posted on 2008-04-23 22:44
ZelluX 阅读(807)
评论(10) 编辑 收藏 所属分类:
Algorithm
Problem
Every bus in the Ekaterinburg city has a special man (or woman) called
conductor. When you ride the bus, you have to give money to the conductor.
We know that there are more then P% conductors and less then Q% conductors.
Your task is to determine a minimal possible number of Ekaterinburg citizens.
我只能说太挫了。。。精度问题搞了半天,看来浮点还是要尽量化成整型再算啊。
1 #include <iostream>
2 #include <cmath>
3
4 using namespace std;
5
6 int main()
7 {
8 double dp, dq;
9 cin >> dp >> dq;
10 int p = floor(dp * 100 + 0.5);
11 int q = floor(dq * 100 + 0.5);
12 for (int i = 1; ; i++) {
13 int a = p * i / 10000;
14 int b = q * i / 10000;
15 if ((a < b) && (q * i % 10000 > 0)) {
16 cout << i << endl;
17 return 0;
18 }
19 }
20 return 0;
21 }
22 还有个问题就是q*i是开区间还是闭区间,总之Wrong Answer了无数次后总算过了。。。