3n+1问题 总是time limit exceeded
来源:学生作业帮 编辑:搜狗做题网作业帮 分类:综合作业 时间:2024/05/21 05:13:41
3n+1问题 总是time limit exceeded
如题.具体问题是,随便给一个数n,如果n是偶数,那么除以2,如果n是奇数,那么3*n+1,这么循环下去,直到达到1为止.当中经过的步骤数量称作cycle length,比如说,8->4->2->1,这个的cycle length就是4.
现在随便给两个数 i 和 j,要求出 i 与 j 当中所有数(包括 i 和 j )的最大的cycle length,然后print出来.例子如下,
Sample Input
1 10
100 200
201 210
900 1000
Sample Output
1 10 20
100 200 125
201 210 89
900 1000 174
我在我自己的电脑上test我的代码,test包括最极端的情况,input是1 999999的情况,运行时间绝对不到1秒.时间要求是3秒以下,但是为什么每次我提交给uvaonlinejudge,它总说我time limit exceeded?
我的代码如下:
#include
#include
#include
#include
#include
#include
using namespace std;
vector array(1000000);
int getcycle(int x)
{
int count=0;
int orgin=x;
while (x = 1) {
if ((x < 1000000) && (array[x] = NULL)) {
count += array[x];
break;
}
else {
float temp = (float)x/2;
float diff = temp - floor(temp);
if (diff==0) {
\x05count++;
\x05x = x/2;
}
else {
\x05count++;
\x05x = 3*x + 1;
}
}
}
array[orgin]=count;
return count;
}
int findmax(int x,int y)
{
int max=0;
int bigger;
int smaller;
if (x
如题.具体问题是,随便给一个数n,如果n是偶数,那么除以2,如果n是奇数,那么3*n+1,这么循环下去,直到达到1为止.当中经过的步骤数量称作cycle length,比如说,8->4->2->1,这个的cycle length就是4.
现在随便给两个数 i 和 j,要求出 i 与 j 当中所有数(包括 i 和 j )的最大的cycle length,然后print出来.例子如下,
Sample Input
1 10
100 200
201 210
900 1000
Sample Output
1 10 20
100 200 125
201 210 89
900 1000 174
我在我自己的电脑上test我的代码,test包括最极端的情况,input是1 999999的情况,运行时间绝对不到1秒.时间要求是3秒以下,但是为什么每次我提交给uvaonlinejudge,它总说我time limit exceeded?
我的代码如下:
#include
#include
#include
#include
#include
#include
using namespace std;
vector array(1000000);
int getcycle(int x)
{
int count=0;
int orgin=x;
while (x = 1) {
if ((x < 1000000) && (array[x] = NULL)) {
count += array[x];
break;
}
else {
float temp = (float)x/2;
float diff = temp - floor(temp);
if (diff==0) {
\x05count++;
\x05x = x/2;
}
else {
\x05count++;
\x05x = 3*x + 1;
}
}
}
array[orgin]=count;
return count;
}
int findmax(int x,int y)
{
int max=0;
int bigger;
int smaller;
if (x
#include
int main(void){
int i,j;
while (scanf("%d%d",&i,&j)!=EOF){
int a,b,max=0;
i
int main(void){
int i,j;
while (scanf("%d%d",&i,&j)!=EOF){
int a,b,max=0;
i
hdoj1032 3n+1问题 time limit exceeded
ACM 的一道题提交总是Time Limit Exceeded,求救
Time Limit Exceeded和Output Limit Exceeded有什么不同,还是一样的?
Bandwidth Limit Exceeded
Output Limit Exceeded这是什么意思?
Call limit is exceeded for your IP
杭电里面的Output Limit Exceeded
杭电ACM2006提示Output Limit Exceeded,
IP Connection Limit Exceeded如何解决
user limit exceeded check your license的汉语意思是什么?
C++的问题 整数的因子数 Time Limit:2000MS Memory Limit:32768K
TIME LIMIT怎么样