Yikara @ 2021-03-21 11:21:19
#include<bits/stdc++.h>
using namespace std;
int main(){
int k,count=0,n,j=0;
cin>>n>>k;
do{
count+=n;//增加总吸烟数
j+=n;//增加烟头
n=0;//烟头数清零(全部吸掉)
n+=j/k;//换烟
j-=j/k;//烟头消耗
}while(j>=k||n>0);//当烟头可以换或还有烟时继续
cout<<count<<endl;
return 0;
}
by Yikara @ 2021-03-21 11:21:55
全部TLE了,O2也没用。这咋会TLE呢
by lxy20080324 @ 2021-03-21 11:23:58
为什么要while呢
by lxy20080324 @ 2021-03-21 11:24:45
不是可以推出公式吗
by lxy20080324 @ 2021-03-21 11:25:13
n+(n-1)/(k-1)
by Yikara @ 2021-03-21 11:26:04
@lxy20080324 emm.....
by Yikara @ 2021-03-21 11:28:57
捞
by duyh1114 @ 2021-03-21 11:32:12
您这j-=j/k
就很迷。为啥烟头要减去换到的烟数
by duyh1114 @ 2021-03-21 11:32:27
@DonaldTrump2016
by konjacq @ 2021-03-21 11:33:28
j-=j/k;//烟头消耗
显然 您这里应该消耗不止