Question Link
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1701
Solution:
I haven't done questions for a long time, I haven't written my ideas about solving problems, I won't even do short answer questions, and the monthly round in the afternoon is suspended. I am miserable and I am complaining here. O (zookeeper) O alas
A good short answer is actually wa, a float trap, more than once. At first, I couldn't understand the question. The number of acmers is between P % and Q %, so P % and Q % cannot be the same, because one is at least and the other is at most. Check the Code:
[CPP]View plaincopy
- # Include <iostream>
- Using namespace STD;
- Int main ()
- {
- Int T, I; Double A, B;
- Cin> T;
- While (t --)
- {
- Cin> A> B;
- For (I = 1; I ++)
- {
- If (INT) (A * I/100) <(INT) (B * I/100 ))
- Break;
- }
- Cout <I <Endl;
- }
- Return 0;
- }
Pay special attention to the floating point type. The following situations often occur.
Wa
# Include <stdio. h> int main (void) {double p, q; double I, K; int N; while (scanf ("% d", & n) = 1) {While (n --) {k = 1.0; scanf ("% lf", & P, & Q); for (I = 1; I ++) {P = P/100; q = Q/100; If (INT) (I * P) <(INT) (I * q) {printf ("%. LF \ n ", I); break ;}}} return 0 ;}
AC
# Include <stdio. h> int main (void) {double p, q; double I, K; int N; while (scanf ("% d", & n) = 1) {While (n --) {k = 1.0; scanf ("% lf", & P, & Q); for (I = 1; I ++) {If (INT) (I * P/100) <(INT) (I * q/100) {printf ("%. LF \ n ", I); break ;}}} return 0 ;}
HDU-1701-ACMer