求各位大佬看看,这怎么优化才能不超时?
  • 板块P1590 失踪的7
  • 楼主lyxleo
  • 当前回复9
  • 已保存回复9
  • 发布时间2020/8/21 13:35
  • 上次更新2023/11/6 19:46:16
查看原帖
求各位大佬看看,这怎么优化才能不超时?
255762
lyxleo楼主2020/8/21 13:35

我的代码能对是能对,就是超时了,求各位帮忙优化一下,感谢。(11,12,13号点超时)

#include <bits/stdc++.h>
using namespace std;
long long t,a,ans;

inline bool check_7(long long num){
	long long ts = num;
	bool not_have_7 = true;//假设没有 
	while(ts){
		if(ts%10 == 7){
			not_have_7 = false;
			break;
		}
		ts/=10;
	}
	return not_have_7;
}

int main(){
	scanf("%lld",&t);
	while(t--){
		ans = 0;
		scanf("%lld",&a);
		for(long long i=1;i<=a;++i){
			if(check_7(i)){//没有 
				++ans;
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}
2020/8/21 13:35
加载中...