关于代码运行效率
  • 板块学术版
  • 楼主Aasino
  • 当前回复17
  • 已保存回复17
  • 发布时间2023/10/13 15:06
  • 上次更新2023/11/2 14:09:20
查看原帖
关于代码运行效率
186040
Aasino楼主2023/10/13 15:06
#include<bits/stdc++.h>
#define y1 yyyy
using namespace std;
const int N=3e5+10;
signed main()
{
	for(int now=1;now<=N;now++){	
		int r=0;
		int l=1;
		while(l<N)
		{
			r=(N-1)/((N-1)/l);
			l=r+1;
		}
	}
	return 0;
}   
#include<bits/stdc++.h>
#define y1 yyyy
using namespace std;
const int N=3e5+10;
signed main()
{
	for(int now=1;now<=N;now++){	
		int r=0;
		int l=1;
		while(l<2*N)
		{
			l=l+sqrt(N);
		}
	}
	return 0;
}   

这两份代码运行效率差距特别大,第二份只要 1s,第一份需要 5s,求解答

2023/10/13 15:06
加载中...