理清思路即可:
代码如下:
C语言:
1.#include<stdio.h> int main() { int N,U,D; scanf("%d%d%d",&N,&U,&D); int number=0; int s=0;//位移距离 while(s<N){ if(number%2==0) s+=U; else s-=D; number++; } printf("%d",number); }
C++:
#include<iostream> using namespace std; int main() { int N,U,D; cin>>N>>U>>D; int number=0; int s=0;//位移距离 while(s<N){ if(number%2==0) s+=U; else s-=D; number++; } cout<<number; }