题目:
小明计划周一到周五每天做a道题目,周六和周日每天做b道题目,请你帮小明计算,按照计划他将在第几天是先做题数大于等于n题?
第一种解法:
#include<iostream>
using namespace std;
int main()
{
long a, b, n, ans=0, temp;
cin >> a >> b >> n;
temp = 5 * a + 2 * b; //一周的刷题量
ans = ans + ((n / temp) * 7); //刷题整周的个数
if (n % temp > 5 * a) //剩余刷题量的个数比5*a多,在周六或者周日刷完题
{
ans = ans + 5; //加上前面的5天
ans = ans + ((n % temp - 5 * a) / b); //在周六那天刷完题
if ((n % temp - 5 * a) % b != 0) //周六刷完之后,还剩,但不足刷一天的时间,就是在周日刷
ans++;
}
else //剩余题量在周一到周五之间就可以刷完
{
ans = ans + (n % temp) / a;
if ((n % temp) % a != 0)
ans++;
}
cout << ans << endl;
return 0;
}
第二种解法:
#include<iostream>
using namespace std;
int main()
{
long a, b, n, sum, cnt; //n是总共的题数量,sum是做题量,cnt是做题天数
cin >> a >> b >> n;
for ( cnt = 1; sum <= n; cnt++ )
{
if (cnt % 7 <= 5 && cnt % 7 >= 1) //周一到周五
sum = sum + a;
else
sum = sum + b;
}
return 0;
}