题目:
Has the prof taken attendance yet?
Student, IME’s
In MaratonIME, as many other groups, some students want to attend lectures just enough to not be flunked by frequency (as we know, in USP, University of Sao Paulo, it is necessary to have 70 percent frequency), however some others are dedicated and try to accomplish the most frequency percent possible, going to school even when they are ill or tired. Curiously, there is not any other kind of students in MaratonIME.
Wood, an old MaratonIME’s member, needs help. He is taking the course MAC4815162342, and attended k of m lectures that were given. Consider that MAC4815162342 has n lectures in total per semester. He ask you to help finding the best way to accomplish his objectives, but, as you are new in MaratonIME, you don’t know the kind of student that he is. Embarassed to ask more, you decide to solve two problems, so there is not way to go wrong.
Input
The input consists of a just one line. In this line, you are given three integers n, m and k, with 1 ≤ n ≤ 107 and 0 ≤ k ≤ m ≤ n.
n is the number of lectures of MAC4815162342 per semester, m is the quantity of lectures that were given and k is the number of lectures attended by Wood.
Output
In the first line, print the minimum number of lectures that Wood needs to attend to accomplish at least 70% frequency, or - 1 if it is impossible to accomplish 70% frequency.
In the second line, print the maximum frequency percent that Wood can accomplish, if he goes to all of the lectures from the next lecture. This value has to be rounded down to the closest integer. Don’t print ‘%’.
Examples
Input
10 5 2
Output
5
70
Input
11 2 1
Output
7
90
Note
On the second example, the maximum percentage that Wood can get is 90.9090.
错因分析:1第二个样例:出勤率达到91%,实际为90%:printf在C语言中输出浮点数的时候都是四舍五入;在这里应为整形处理;
2按照数学条件思维直接忽略极端的情况,为负数
3ceil向上取整
floor向下取整
if(n*0.7-k<0)//遗漏这一种情况,没有考虑已达到出勤率
{
printf("0\n");
printf("%d\n",d);
}
AC代码:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
double n,m,k;
int d,t;
while(~scanf("%lf %lf %lf",&n,&m,&k))
{
d=(k+n-m)/n*100;//d应为整形,若为lf,遵循四舍五入;
if(n*0.7-k<0)//遗漏这一种情况,没有考虑已达到出勤率
{
printf("0\n");
printf("%d\n",d);
}
else if((n-m)<n*0.7-k)
{
printf("-1\n");
printf("%d\n",d);
}
else if((n-m)>=n*0.7-k)
{ t=ceil(n*0.7-k);//向上取整
printf("%d\n",t);
printf("%d\n",d);
}
}
return 0;
}
新的表示方法
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
double n,m,k,d;
int t;
while(~scanf("%lf %lf %lf",&n,&m,&k))
{
d=floor((k+n-m)/n*100);//d应为整形,若为lf,遵循四舍五入;向下取整
if(n*0.7-k<0)//遗漏这一种情况,没有考虑已达到出勤率
{
printf("0\n");
printf("%.0lf\n",d);
}
else if((n-m)<n*0.7-k)
{
printf("-1\n");
printf("%.0lf\n",d);
}
else if((n-m)>=n*0.7-k)
{ t=ceil(n*0.7-k);//向上取整
printf("%d\n",t);
printf("%.0lf\n",d);
}
}
return 0;
}