5 条题解
-
3
一天一天过
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int m, k; cin >> m >> k; //m: 当前手头的钱 //k: 每k元送一元 int ans = 0;//过了多少天 int cnt = 0;//花了多少钱 while(1){ //花了一块钱,过了一天 m-=1; ans+=1; cnt+=1; //送钱 if(cnt%k==0) m+=1; if(m==0) break; } cout<<ans<<"\n"; return 0; }
k天k天过
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int m, k; cin >> m >> k; //m: 当前手头的钱 //k: 每k元送一元 int ans = 0;//过了多少天 while(1){ //花k块钱,过k天 m-=k; ans+=k; m+=1; if(m<k) break; } cout<<ans+m<<"\n"; return 0; }
-
1
非常详细版
#include <bits/stdc++.h> using namespace std; int m,k,nowday,num;//m、k、目前天数、花费金额 int main() { cin>>m>>k;//引进m和k while(1)//无限循环 { num+=1;//每天花费1元 nowday+=1;//目前天数加1天 m-=1;//总钱数减1元 if(num==k)//当花费金额到了赠1元的金额时 { num-=k;//现花费金额清零 m+=1;//总钱数加上赠送的1元 } if(m==0)//如果没钱了 { break; } } cout<<nowday; return 0; }
- 1
信息
- ID
- 1221
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 5
- 标签
- 递交数
- 187
- 已通过
- 71
- 上传者