你能告诉我如何优化我的代码吗? [英] Can you please tell me how to optimize my code

查看:85
本文介绍了你能告诉我如何优化我的代码吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

疑问句。链接



https://www.codechef.com/LTIME64B / problems / JDELAY [ ^ ]







ques. link

https://www.codechef.com/LTIME64B/problems/JDELAY[^]



#include<bits/stdc++.h>

using namespace std;

int main (void){
	int t,n,input1,input2,count=0;
	cin>>t;
	for(int i=0;i<t;t++){
		cin>>n;
		for(int j=0;j<n;j++){
			cin>>input1;
			cin>>input2;
			if((input2-input1)>5)
			count++;
		}
		cout<<count;
	}
}





我的尝试:



尝试了很多方法,但未能达到1秒编译时间的标记



What I have tried:

tried many approaches but was not able to go below the mark of 1sec compilation time

推荐答案

我真的不知道一种加速代码的简单方法,但是,无论如何,它看起来都不正确。

尝试

I really don't know a simple way to speed up your code, but, anyway, it looks incorrect.
Try
using namespace std;

int main (void){
	int t,n, input1, input2;
	cin>>t;
	for(int i=0;i<t;t++){
        int count = 0;
		cin>>n;
		for(int j=0;j<n;j++){
			cin>>input1;
			cin>>input2;
			if((input2-input1)>5)
			count++;
		}
		cout << count << '\n';
	}
}


这篇关于你能告诉我如何优化我的代码吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆