#12127: 第五測資點TLE


eechiu (eechiu)


#include <iostream>
using namespace std;
int main()
{
int a,b,n,m;
while(cin>>a>>b)
{
n=0;
for(int i=a; i<=b; i++)
{
if(i%2==0)
{
n++;
}
m=n;
}
cout<<m<<endl;
}
return 0;
}

我的程式碼是這樣的 不過第五測資點卻一直TLE 求救~~

#12138: Re:第五測資點TLE


who_am_I (kruztw)


#include
using namespace std;
int main()
{
int a,b,n,m;
while(cin>>a>>b)
{
n=0;
for(int i=a; i<=b; i++)
{
if(i%2==0)
{
n++;
}
m=n;
}
cout<<m<<endl;
}
return 0;
}

我的程式碼是這樣的 不過第五測資點卻一直TLE 求救~~


如果a 、 b範圍很大

那豈不是要跑很久?

反正,正整數不是奇數就是偶數

應該可以把他們的範圍除以2

再判斷邊界(a跟b的值)稍作調整 (不細講囉,自己研究)

 

如果有幫到忙

還煩請幫忙衝衝人氣

http://ntnuee40475032h.pixnet.net/blog

謝啦~~~