为啥只得了90分,样例三wa

P1150 Peter 的烟

stupid250 @ 2024-08-22 00:18:30

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k,sum;
    cin>>n>>k;
    sum=n;
    while(n/k>=1){
        sum+=n/k;
        n/=k;
    }
    cout<<sum;
    return 0;
}

by xxasmcd @ 2024-08-22 06:52:16

这个代码只计算了初始所给的 n 根烟能产生的烟数量,漏洞在于用烟蒂换来的烟还会产生一个烟蒂。 hack数据:11 3 应输出:16 实际:15


by zhaoyikuan @ 2024-08-22 12:37:09

@stupid250 程序这么改:

#include<iostream>
using namespace std;
int main()
{
    long long n, k, sum = 0;
    cin >> n >> k;
   sum = n;
    while(n >= k)
    {
        n-=k;
        sum++;
        n++;//吸一根加一根
    }
    cout<<s;
}

by zhaoyikuan @ 2024-08-22 12:38:26

不好意思最后那个sum打了个s实在抱歉


by zhaoyikuan @ 2024-08-22 12:39:26

#include<iostream>
using namespace std;
int main()
{
    long long n, k, sum = 0;
    cin >> n >> k;
    sum = n;
    while(n >= k)
    {
        n-=k;
        sum++;
        n++;
    }
    cout<<sum;
}

by stupid250 @ 2024-08-22 14:44:09

感谢大佬相助


by stupid250 @ 2024-08-22 14:44:54

@zhaoyikuan 谢谢


by stupid250 @ 2024-08-22 14:45:14

@xxasmcd 多谢


|