蓝桥杯入门培训 C/C++(录屏)
kafkaSbj:
学会递归回溯暴力解题[嗑瓜子]省一没啥问题
【回复】回复 @小羊旎奥 :现在很多题都是限制了时间和内存的,递归的时间绝对会超
【回复】回复 @弹性波动力学 :什么意思?是现在不能用了吗?
我就知道是你_:
#include <iostream>
using namespace std;
int main() {
int m = 2019, n = 324;
//int m=5, n=3;
int cnt = 0;
int temp;
while(n>0) {
m = m - n; cnt++;
if(m<n) {
temp = m; m = n; n = temp;
}
}
// 法2:使用整除和模运算写法
// while(true) {cout << cnt << " " << m << " " << n << endl;
// cnt += m/n;
// temp = m%n; if(temp==0) break;
// m = n;
// n = temp; //cout << m << " " << n << endl;
// }
cout << cnt << endl; //5*3, cnt=4; 2019*324, cnt=21
return 0;
}
录屏 直播录像 竞赛 蓝桥杯