首页 > 试题广场 >

出专辑

[编程题]出专辑
  • 热度指数:10811 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解

你作为一名出道的歌手终于要出自己的第一份专辑了,你计划收录 n 首歌而且每首歌的长度都是 s 秒,每首歌必须完整地收录于一张 CD 当中。每张 CD 的容量长度都是 L 秒,而且你至少得保证同一张 CD 内相邻两首歌中间至少要隔 1 秒。为了辟邪,你决定任意一张 CD 内的歌数不能被 13 这个数字整除,那么请问你出这张专辑至少需要多少张 CD ?


输入描述:

每组测试用例仅包含一组数据,每组数据第一行为三个正整数 n, s, L。 保证 n ≤ 100 , s ≤ L ≤ 10000



输出描述:

输出一个整数代表你至少需要的 CD 数量。

示例1

输入

7 2 6

输出

4
js v8
while (line = readline()) {
    var arr = line.split(' ')
    var n = parseInt(arr[0]), s = parseInt(arr[1]), ll = parseInt(arr[2])
    var cd = 1, count = 0, l = ll, r = Math.floor((ll - s) / (s + 1) + 1)
    while (n > 0) {
        if (l >= s) {
            if (((count + 1) % 13 !== 0)) {
                if (count === 0) {
                    l -= s;
                } else {
                    l -= (s + 1);
                }
                count++
                n--
            } else if ((l > (2 * s + 2)) && (n >= 2) || ((n < r) && (l > s + 1)) && (cd !== 1)) {
                l -= (2 * (s + 1));
                count = count + 2
                n -= 2
            } else {
                cd = cd + 1
                count = 0
                l = ll
            }
        } else {
            cd = cd + 1
            count = 0
            l = ll
        }
    }
    console.log(cd)
}


发表于 2020-02-14 19:04:17 回复(0)
case:27 1 27的时候,为什么不是两张专辑,一张14首,一张13首,第一张14+13=27秒满足要求呀,为什么答案是3张呢?
发表于 2017-05-23 12:35:56 回复(0)
var count_per = Math.floor((l + 1) / (s + 1)) if (count_per % 13 === 0) { count_per-- } var count = Math.ceil(n / count_per) var more = n % count_per // 如果剩下来的歌为13的倍数,且无法向前面的专辑借歌,则需要增加一张专辑: // 1. 一张专辑的歌曲容量肯定比剩下来的歌多,如果只多1,增加一张专辑 // 2. 如果当前专辑数为1,增加一张专辑 if (more != 0 && more % 13 === 0 && (count_per - more === 1 || count === 1)) { count++ } console.log(count);
编辑于 2017-03-21 22:20:43 回复(1)
process.stdin.resume();
process.stdin.setEncoding('ascii');
var input = "";
var input_array = "";
var n;
var s;
var l;
process.stdin.on('data', function (data) {
input += data;
});
function do_something(n, s, l){
//你的代码
var song = Math.floor((l+1)/(s+1));
if(song%13=== 0){
song--;
}
var amount_cd = Math.ceil(n/song);
var last_cd = n%song;
if(amount_cd === 1){
if(n%13=== 0){
amount_cd += 1;
}
}else{
if(last_cd%13=== 0&& ((last_cd*(s+1)+s)>=l)){
amount_cd += 1;
}
}
console.log(amount_cd);
}
process.stdin.on('end', function () {
input_array = input.split("\n");
var nLine = 0;
while(nLine < input_array.length){
var line = input_array[nLine++].trim();
if(line === ''){
continue;
}
var input_arrays = line.split(' ');
n = +input_arrays[0];
s = +input_arrays[1];
l = +input_arrays[2];
do_something(n, s, l);
}
});

编辑于 2016-08-21 16:16:23 回复(0)
process.stdin.resume();
process.stdin.setEncoding('ascii');

var input = "";
var input_array = "";
var n;
var s;
var l;

process.stdin.on('data', function (data) {
    input += data;
});

function do_something(n, s, l){
//你的代码
    var count=0;
    while(count<(l+1)/(s+1)&&(count+1)<(l+1)/(s+1)){
        count++;
    }
    if(count==0){
        console.log(1);
        return ;
    }
    if(count%13==0&&count!=0){
        count--;
    }
    var left=n%count;
    var now=parseInt(n/count);
    if(left%13==0&&left!=0){
if(now!=0&&left+1<count){
console.log(now+1)
}
else
        console.log(now+2);
    }
    else if(left==0){
        console.log(now);
    }
    else{
        console.log(now+1);
    }
}

process.stdin.on('end', function () {
    input_array = input.split("\n");
    var nLine = 0;
    while(nLine < input_array.length){
        var line = input_array[nLine++].trim();
        if(line === ''){
            continue;
        }
        var input_arrays = line.split(' ');
        n = +input_arrays[0];
        s = +input_arrays[1];
        l = +input_arrays[2];
     
do_something(n, s, l);
        
    }
});
发表于 2016-08-18 16:53:09 回复(0)
function do_something(n, s, l){
var i=1;
    if(l<s)return;
    while(s*i+i-1<l)
        {
            i=i+1;
        }
    if(!(i%13)){i=i-1;}
    if(n%i) console.log(parseInt(n/i)+1)
    else console.log(parseInt(n/i))//你的代码
}
测试用例有问题
发表于 2016-07-30 14:50:27 回复(1)