随机数代码TLE,求调
查看原帖
随机数代码TLE,求调
1035258
Gary0504楼主2024/11/6 23:14

班上两个蒻至daolao想挑战不可能(赌阳寿),于是写了一份随机数代码,但TLE了,求调。

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
bool ans;
int r,c,s;
inline void run(){
   int n,q;
   ans=0;
   cin>>n>>s>>q;
   while(q--){
   cin>>r>>c;
   	cout<<rand()%2<<endl;
   }
}
int main(){
   srand(time(0));
   int T;
   cin>>T;
   while(T--) run();
//	printf("Time used=%.2f\n",(double)clock()/CLOCKS_PER_SEC);
   return 0;
}

提交记录

but

如果把run函数的while里面的输入注释掉,就不会TLE

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
bool ans;
int r,c,s;
inline void run(){
	int n,q;
	ans=0;
	cin>>n>>s>>q;
	while(q--){
	//cin>>r>>c;
		cout<<rand()%2<<endl;
	}
}
int main(){
	srand(time(0));
	int T;
	cin>>T;
	while(T--) run();
//	printf("Time used=%.2f\n",(double)clock()/CLOCKS_PER_SEC);
	return 0;
}


提交记录

希望有好心人帮忙看一看!!!

2024/11/6 23:14
加载中...