这道题没用到任何算法,所以是道简单题,但是有些地方值得注意。
首先这道题的题意乍一看让人有点不明白,其实这道题目给出了ACMer的百分比范围,所以总的学生人数分别乘以P和Q至少得出的人数要相差1,又由于题目求最少学生人数,所以题目就是让你算总的学生人数分别乘以P和Q得出的人数相差1时的总学生数(因为如果总学生数越多,对于同样的P和Q,求出来的值相差就越多,反过来,如果求出的差值越小,总学生数就越少)。
其次,要注意浮点数的问题,在读入P和Q之后不要立即除以100,因为计算机在处理浮点数时并不像处理整型数那样精确,存在一些小误差。在这道题中,如果Q/100后,在用VC6.0调试的时候会发现此时计算机储存的不是0.14100000000000000而是0.14099999999999999。此外这种误差并不会出现在所有浮点数上,有些是和我们的想法是一致的,有些则如上那样有误差。如果你先用学生数*百分比,再除以100,可以避免掉有误差产生的浮点数。(当然这是我的推测)也许有人会问这点小误差正的会影响AC吗?事实上,在实际测试中正的会有影响。
最后就是要取下整,这里我也感觉很奇怪,所以希望明白的人给以指点!!!
代码(G++):
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int t,c,t1,t2;
double p,q;
cin>>t;
while(t--)
{
cin>>p>>q;
c=1;
while(int(c*q/100)-int(c*p/100)<1) c++;
cout<<c<<endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
附上原题:
ACMer
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Problem Description
There are at least P% and at most Q% students of HDU are ACMers, now I want to know how many students HDU have at least?
Input
The input contains multiple test cases.
The first line has one integer,represent the number of test cases.
The following N lines each line contains two numbers P and Q(P < Q),which accurate up to 2 decimal places.
The first line has one integer,represent the number of test cases.
The following N lines each line contains two numbers P and Q(P < Q),which accurate up to 2 decimal places.
Output
For each test case, output the minumal number of students in HDU.
Sample Input
1 13.00 14.10
Sample Output
15