全部评论
就是个数学推公式
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
rl.on('line', function(line) {
line = line.split(' ');
var x = +line[0],
f = +line[1],
d = +line[2],
p = +line[3];
if (d === 0) {
console.log(0)
} else if (parseInt(d / x) <= f) {
console.log(parseInt(d / x))
} else {
var rest = d - x * f;
var day = Math.floor(rest / (x + p));
console.log(f + day);
} })
原来前端的题目都一样呀
function mostDays(x,f,d,p) {
if(Math.floor(d/x)<=f) {
return Math.floor(d/x);
} else {
return (f+(Math.floor((d-x*f)/(x+p))));
}
} 我的做法是不是太lowB了
第三题是那个能活多少天的吗。。感觉是最简单的了= =
贪心算法 100通过
相关推荐
06-23 17:59
北京师范大学 Java 点赞 评论 收藏
分享