Gym-101502K Malek and Summer Semester
题意:
M这学期修了n门课,给出这些课的分数,判断这学期M是否通过。
M要通过这学期,必须至少通过ceil(n*m)门课。
m输入会给出,一门课的成绩>=50才算做通过。
ceil(x)是大于或等于x的最小的整数,例如:ceil(0.95)=1, ceil(4)=4, ceil(7.001)=8。
做法:
(1)
直接使用c的库函数ceil()。
ceil()返回不小于其参数的最小整数值。这个值以double的形式返回。
与之相关的floor()返回不大于其参数的最大整数值。
(2)
自己动手写一个简单的my_ceil(),见代码。
(1)
#include <stdio.h>
#include <math.h>
int
main() {
int t, n, i, score, sum, o;
double m;
scanf("%d", &t);
while( t-- ) {
scanf("%d %lf", &n, &m);
i = n;
sum = 0;
while( i-- ) {
scanf("%d", &score);
if( score >= 50 ) {
sum++;
}
}
o = ceil(n * m);
if( sum >= o ) {
printf("YES\n");
}
else {
printf("NO\n");
}
}
return 0;
}
(2)
#include <stdio.h>
int
my_ceil(double x) {
int ans;
ans = x;
if( ans == x ) {
return ans;
}
else {
return ans + 1;
}
}
int
main() {
int t, n, i, score, sum, o;
double m;
scanf("%d", &t);
while( t-- ) {
scanf("%d %lf", &n, &m);
i = n;
sum = 0;
while( i-- ) {
scanf("%d", &score);
if( score >= 50 ) {
sum++;
}
}
o = my_ceil(n * m);
if( sum >= o ) {
printf("YES\n");
}
else {
printf("NO\n");
}
}
return 0;
}