【FOJ】Problem 1150 Farmer Bill's Problem

Problem 1150 Farmer Bill’s Problem.

The meaning of problems

  • butts - butts
  • That there are n cigarettes, k a cigarette butt can change a cigarette, asked if he could have a few smoke

Thinking

  • Currently P cumulative number of cigarettes have expressed ciga, butt this time represents the number of the hands of cigarette butts P
  • Round:
    Ciga Ciga = Butt + / K (+ accumulation cigarette butts can be exchanged for hand cigarette)
    Butt = Butt / Butt% K + K (for the exchange of smoked cigarettes on a cigarette + no out against cigarette butts)
  • When butt <k i.e. insufficient exchange cigarette butts hand, when the output end of the cycle

Code

#include<cstdio>
using namespace std;

int main(){
	int n, k, butt, ciga;
	while(scanf("%d%d", &n, &k)!=EOF){
		ciga = n;
		butt = n;
		while(butt>=k){
			ciga += butt/k;
			butt = butt/k + butt%k;
		}
		printf("%d\n", ciga);
	}
	return 0;
}
Published 28 original articles · won praise 0 · Views 318

Guess you like

Origin blog.csdn.net/qq_44531167/article/details/105299192