2 3不对

P1150 Peter 的烟

Lvyuze @ 2021-08-06 14:45:30

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int n,k,a;
int main()
{
cin>>n>>k;
a=n/k;
n+=a;
cout<<n<<endl;
return 0;
}

by AlbrecRoon @ 2021-08-06 14:49:03

献上蒟蒻代码

#include<cstdio>
int n,k,h = 0;
int f(int a)
{
    if(!a) return 0;
    int d = a / k;
    h += a % k;
    int c = 0;
    if(h >= k)
    {
        c = h / k;
        h %= k;
    }
    return a + f(d) + c;
}
int main()
{
    scanf("%d%d",&n,&k);
    printf("%d",f(n));   
    return 0;
}

by Lvyuze @ 2021-08-06 14:50:39

@AlbrecRoon 能不能不用函数啊啊啊啊啊啊啊?这题感觉没必要。。。。。。。。。


by AlbrecRoon @ 2021-08-06 14:53:25

@Lvyuze 用函数怎么了.......


by Lvyuze @ 2021-08-06 14:55:33

@AlbrecRoon 不会。。。。。。。。。。。。。。。。。。。。。。。。


by BlankAo @ 2021-08-06 14:55:52

@Lvyuze 你换来的新烟头可以再换新新烟头


by Lvyuze @ 2021-08-06 14:57:27

@BlankAo 哦哦哦哦,明白了,我再改改


by Lovely_day @ 2021-08-06 15:15:15

应该是(n-1)/(k-1)+n

k个烟蒂=1个烟蒂+1根香烟

所以(k-1)个烟蒂=1根香烟

减去最后一个得(n-1)/(k-1)+n


by Lvyuze @ 2021-08-06 15:19:00

@BlankAo 过了,谢谢大佬!


|