题目很简单:
给两个浮点数p, q做为输入,两个浮点数都是精确到小数位后面两位。
要求一个数x使得[x*p, x *q]中至少有一个整数出现。
当然输入13表示13%
http://acm.timus.ru/problem.aspx?space=1&num=1011
1011. Conductors
Time Limit: 2.0 second
Memory Limit: 16 MB
Memory Limit: 16 MB
Background
Everyone making translations from English to Russian knows an English phrase "Naked conductor runs along the bus". It has two very different meanings.
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.
Input
Two numbers
P,
Q such that 0.01 ≤
P,
Q ≤ 99.99. Numbers are given with 2 digits precision. These numbers are separated by some spaces or "end of line" symbols.
Output
The minimal number of Ekaterinburg citizens.
Sample
input | output |
---|---|
13 14.1 | 15 |
粘个代码吧。写得比较挫
#include<stdio.h>
#include<stdlib.h>
double p, q;
double from, to, x;
int pp, qq;
int main(void)
{
while (scanf("%lf%lf", &p, &q) != EOF)
{
p *= 100.0; q *= 100.0; x = 1;
while (1)
{
pp = (int)(p * x);
qq = (int)(q * x);
if(qq/10000-pp/10000>=1 && qq%10000 && pp % 10000) break;
x = x + 1;
}
pp = x;
printf("%d\n", pp);
}
return 0;
}
这个题实际上要考虑的东西还比较多。
1、两位小数,所以得乘上100
2、取整的话需要除10000.
我反正是错了N遍