12=2x6 12= 3x4 12=12 具体要求见图片，我自己写的代码总是超时，哪位好心的大神帮忙看看 这题怎末破

`````` flag = 0
s = input()
num = int(s)
num1 = num
num2 = str(num)
s1 = []
s = num2+'='
i = 2
if num == 1:
print('1=1')
flag = 1
if num == 0:
print('0=0')
flag =1
while flag == 0:
if num%i == 0:
if num/i<i:
i = num
s1.append(int(i))
num = num/i
if num==1:
s = str(num2)+'='
for j in range(0,len(s1)):
if j< len(s1)-1:
s = s+str(s1[j])+'*'
else:
s = s+str(s1[j])
print(s)
if len(s1)>1:
a = i * s1[len(s1)-2]

b = s1[len(s1)-2]
if a / (b+1) < (b+1):
s1.pop()
s1.pop()
num = a
i = a
else:
s1.pop()
s1.pop()
b = b+1
while not a%b==0:
b = b+1
num = a
i = b
else:
flag=1

else:
i = i + 1

``````

3个回答

time limit exceeded!!为什么？？？
[code=C/C++]rn#includernint main()rn int i,n,a[2];rn for(i=0;i<2;i++)rn rn scanf("%d",&n);rn a[i]=(1+n)*n/2;rn rn for(i=0;i<2;i++)rn rn printf("%d\n\n",a[i]);rn rn return 0;rnrn[/code]rn怎么会time limit exceeded呢？？
Time limit exceeded怎么回事啊？

leetcode 提示Time Limit Exceeded
rt, 题目如下rnYou are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.rnrnInput: (2 -> 4 -> 3) + (5 -> 6 -> 4)rnOutput: 7 -> 0 -> 8rnrn我的代码是rn[code=c] rnclass Solution rnrnpublic:rnrn ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) rn rnrn if (l1 == NULL) return l2; rn if (l2 == NULL) return l1;rn ListNode* p = l1;rn ListNode* q = l2;rn ListNode* r = NULL; //指向当前结点的前趋rn int Psum = 0;rn while ( p && q )rn rn rn int sum = p->val + q->val + Psum;rn int Nsum = sum%10; //rn p->val= Nsum;rn Psum = sum/10; // 和 是否大于10rn r=p; rn p=p->next;rn q=q->next;rn rn rn while (q)rn rn rn int tmp = (q->val + Psum)%10;rn Psum = tmp/10;rn r->next = new ListNode (tmp);rn r=r->next;rn rn rn while (p)rn rn rn p->val = (p->val + Psum)%10;rn Psum = p->val/10; rn rn rn if ( Psum ) rn ListNode* v= new ListNode (Psum);rn r->next = v;rn r=v;rn rn return l1;rn rn;[/code]rnrn我的思路是先处理两个链表长度相同的部分, 然后把相加得到的和直接赋值给第一个链表, 对于超出部分, 则新建结点, 然后接到第一个链表上. 请问哪里错了..
Leetcode提交代码Time Limit Exceeded

Problem DescriptionrnYour task is to calculate the sum of some integers.rnrnInputrnInput contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line. rnrnOutputrnFor each group of input integers you should output their sum in one line, and you must note that there is a blank line between outputs.rnrnSample Inputrn3rn4 1 2 3 4rn5 1 2 3 4 5rn3 1 2 3rnrnSample Outputrn10rnrn15rnrn6rn#include rn#include rnrnint main()rnrn int n,m1,m2,m3;rn int sum1=0,sum2=0,sum3=0;rn int temp;rn scanf("%d",&n);rn while(--n)rn rn scanf("%d",&m1);rn while(m1--)rn rn scanf("%d",&temp);rn sum1 += temp;rn rn scanf("%d",&m2);rn while(m2--)rn rn scanf("%d",&temp);rn sum2 += temp;rn rn scanf("%d",&m3);rn while(m3--)rn rn scanf("%d",&temp);rn sum3+=temp;rn rn printf("%d\n\n%d\n\n%d\n\n",sum1,sum2,sum3);rn rn return 0;rn rn

POJ1002遇到Time Limit Exceeded问题

1482 Memory Limit Exceeded
http://acm.zju.edu.cn/show_problem.php?pid=1482rnrn#include rnchar maze[3001][3001];rn rnvoid f(int s,int h)rnrn if(maze[s][h]==0)rn rn maze[s][h]=1;rn f(s,h+1);rn f(s-1,h);rn f(s,h-1);rn f(s+1,h);rn rnrnrnrnrnint main()rnrn int size,s,h;rn int staus,count=0;rn cin>>size;rn for(h=0;h<=size+1;h++)rn for(s=0;s<=size+1;s++)rn maze[s][h]=1;rn for(s=1;s<=size;s++)rn for(h=1;h<=size;h++)rn rn cin>>staus;rn maze[s][h]=staus;rn rn for(s=1;s<=size;s++)rn for(h=1;h<=size;h++)rn rn if(maze[s][h]==0)rn rn count++;rn f(s,h);rn rn rn cout<
【数据结构与算法】[hihoCode] #1015 : KMP算法（解决Time Limit Exceeded）

hihoCoder上的一道关于KMP算法的一道题，题目描述如下：n#1015 : KMP算法n时间限制:1000msn单点时限:1000msn内存限制:256MBn描述n小Hi和小Ho是一对好朋友，出生在信息化社会的他们对编程产生了莫大的兴趣，他们约定好互相帮助，在编程的学习道路上一同前进。nn这一天，他们遇到了一只河蟹，于是河蟹就向小Hi和小Ho提出了那个经典的问题：“小Hi和小Ho，你们能不能够判断一段文字（原串）里面是不是存在那么一些……特殊……的文字（模式串）？”nn小Hi和小Ho仔细思考了一下，觉得只能想到很简单的做法，但是又觉得既然河蟹先生这么说了，就肯定不会这么容易的让他们回答了，于是他们只能说道：“抱歉，河蟹先生，我们只能想到时间复杂度为（文本长度 * 特殊文字总长度）的方法，即对于每个模式串分开判断，然后依次枚举起始位置并检查是否能够匹配，但是这不是您想要的方法是吧？”nn河蟹点了点头，说道：”看来你们的水平还有待提高，这样吧，如果我说只有一个特殊文字，你能不能做到呢？“nn小Ho这时候还有点晕晕乎乎的，但是小Hi很快开口道：”我知道！这就是一个很经典的模式匹配问题！可以使用KMP算法进行求解！“nn河蟹满意的点了点头，对小Hi说道：”既然你知道就好办了，你去把小Ho教会，下周我有重要的任务交给你们！“nn”保证完成任务！”小Hi点头道。nn提示一：KMP的思路nn提示二：NEXT数组的使用nn提示三：如何求解NEXT数组nn输入n第一行一个整数N，表示测试数据组数。nn接下来的N*2行，每两行表示一个测试数据。在每一个测试数据中，第一行为模式串，由不超过10^4个大写字母组成，第二行为原串，由不超过10^6个大写字母组成。nn其中N<=20nn输出n对于每一个测试数据，按照它们在输入中出现的顺序输出一行Ans，表示模式串在原串中出现的次数。nn样例输入n5nHAnHAHAHAnWQNnWQNnADAnADADADAnBABABBnBABABABABABABABABBnDADnADDAADAADDAAADAADn样例输出n3n1n3n1n0nn这是我按照自己的理解提交的代码：n#includen#includen#includennint KMP(char *ori,char *pat);nnint main(void)nn char *ori,strori[10001];n char *pat,strpat[1000001];n int n;//测试组数nn pat=strpat;//必须初始化 有所指向才行n ori=strori;n scanf("%d\n",&n);n while(n--)n n scanf("%s",pat);n scanf("%s",ori);n printf("%d\n",KMP(ori,pat));n n return 0;nnnint KMP(char *ori,char *pat)nn char *temp,*p;n int num=strlen(pat);n int i=0,j=0;n int *next;n int sum=0;nn//求出next数组n next=(int *)malloc(num*sizeof(int));n memset((int *)next,0,num*sizeof(int));n p=temp=pat;n pat++;n while(*pat)n n if(*pat==*temp)n n *(next+i+1)=j+1;n pat++;n temp++;n j++;n n elsen n pat++;n j=0;n n i++;n nn //匹配字符串n pat=temp=p;n i=j=0;n while(*ori)n n if(*ori!=*pat)n n ori++;n if(i!=0)//表明之前有匹配成功过，但还未完全匹配n n ori=ori-1-*(next+i-1);//ori=ori-i-1+(i-*(next+i-1));n pat=p;n i=0;n n nn elsen n ori++;n pat++;n i++;n if(*pat=='\0')n n sum++;n ori=ori-1-*(next+i-1);n pat=p;n i=0;n n n n return sum;nnn但每次提交结果都是：nTime Limit Exceeded TLE 用户程序运行时间超过题目的限制n怎么优化一下我的代码才能是它AC啊？！求大神指导啊。

Total Submission: 825 Submission Accepted: 114 rnrnrnrnDescriptionrnrn有N个数字是来自一个长度为N+1的连续整数序列，但是给你的并不是有序的，请你帮忙找出来是缺失的那个数字是在序列的两边还是中间rnrnInputrnrn有多组测试数据，每组测试数据包括2行，第一行包括一个整数N(0rnusing namespace std;rnint a[10000];rnint main()rnint n,max,min,j=1;rnwhile(cin>>n&&n!=0)rnmax=-234567890;rnmin=234567890;rn for(int i=1;i<=n;i++)rn cin>>a[i];rn if(a[i]>max)max=a[i];rn if(a[i]
ACM简单题目 Time Limit Exceeded 求解释
ACM简单题目 Time Limit Exceeded 求解释rn月老使命rnTime Limit: 1000 ms Case Time Limit: 1000 ms Memory Limit: 64 MBrnTotal Submission: 26 Submission Accepted: 3rnDescriptionrncxlove曾经客串过月老(呵呵~~~只不过是给数字配对)。rn两个整数拼接成一个新数字之后，如果是3的倍数，则我们定义为幸福配对。rn现在有n个数字，月老的任务就是将其配对。rn现在请你帮助月老计算出最多能够有多少个幸福配对。rn例如：123和456可以拼接成123456，也可以组成456123。rnrnInputrn一个整数 T，表示有 T 组测试数据。（1<=T<=40）rn每组数据输入格式如下：rn对于每一组数据，输入如下：rn一个整数n (1<=n<=10000)rn接下来一行，n个整数 a1,a2,a3……an (1<=ai<=1000000000)rnrnOutputrn对于每一组数据，输出一个整数，表示最多配成多少对rnrnSample InputrnOriginal Transformedrn2rn3rn1 2 3rn4rn1 1 4 4rnrnSample OutputrnOriginal Transformedrn1rn0rnrn[code=c]#includernint main()rnrn int T,n,a[10001],i,j,sum;rn scanf("%d",&T);rn while(T--)rn rn sum=0;rn scanf("%d",&n);rn for(i=1;i<=n;i++)rn scanf("%d",&a[i]);rn for(i=1;i
ACM 的一道题提交总是Time Limit Exceeded，求救

hdoj 1043 八数码已编码 Time Limit Exceeded
#includen#includen#includen#includenusing namespace std;ntypedef int state[9]; nconst int maxstate=1000000;nstate st[maxstate],goal=1,2,3,4,5,6,7,8,0;nint dist[maxstate];nchar record[maxstate]; //前一个状态到这一个的移动nint father[maxstate];//记录夫节点配合record【】nint vis[362880];nint fact[9];nconst int dx[4]=-1,1,0,0;nconst int dy[4]=0,0,-1,1;nconst char dir[4]='u','d','l','r';nvoid init_lookup_table()nn fact[0]=1;n for(int i=1;i<9;i++)n fact[i]=fact[i-1]*i;nnint try_to_insert(int s) //编码nn int code=0;n for(int i=0;i<9;i++)n n int cnt=0;n for(int j=i+1;j<9;j++)n if(st[s][j]=0&&newx<3&&newy>=0&&newy<3)n n state& t=st[rear];n memcpy(&t,&s,sizeof(s));n t[newz]=s[z];n t[z]=s[newz];n dist[rear]=dist[front]+1;n if(try_to_insert(rear)) //如果这个状态未被访问n n father[rear]=front;n record[rear]=dir[d];n rear++;n n n n front++;n n return 0;nnint main(void)nn char ch[100];n int index;n while(gets(ch)!=NULL) //输入n n index=0;n memset(vis,0,sizeof(vis));n memset(dist,0,sizeof(dist));n for(int i=0;i<100;i++)n n if(ch[i]>='0'&&ch[i]<='9')n st[1][index++]=ch[i]-'0';n else if(ch[i]=='x')n st[1][index++]=0;n n int ans=bfs();n if(ans>0)n n string str;n int v=ans;n int k=dist[ans];n while(k--)n n str.push_back(record[v]); //路径生成n v=father[v];n n for(int i=str.length()-1;i>=0;i--)n printf("%c",str[i]);n printf("\n");n n elsen printf("unsolvable\n");n n return 0;nn
PAT1019 数字黑洞 提交时Time Limit Exceeded
//PAT1019V1rn#include rnrnint FeiDiZeng(int n)rn int a[4];rn a[0]=n%10; //gern a[1]=n/10%10; //shirn a[2]=n/100%10; //bairn a[3]=n/1000; //qianrn int tmp,i,j;rn for(i=0;i<3;i++)rn for(j=i+1;j<4;j++)rn if(a[i]a[j])rn tmp=a[j];rn a[j]=a[i];rn a[i]=tmp;rn rn rn rn return a[0]*1000+a[1]*100+a[2]*10+a[3]; rnrnrnint main()rn int n,a[4];rn scanf("%d",&n);rn a[0]=n%10; //gernrn a[1]=n/10%10; //shirn a[2]=n/100%10; //bairn a[3]=n/1000; //qianrnrn// if(a[0]==a[1]==a[2]==a[3]) //debugrn if(a[0]==a[1]&&a[1]==a[2]&&a[2]==a[3]) rn printf("%d - %d= 0000",n,n);rn rn elsern int FDZ=FeiDiZeng(n),FDJ=FeiDiJian(n); rn while(FDZ-FDJ!=6174)rn const int result=FDZ-FDJ;rn printf("%04d - %04d = %04d\n",FDZ,FDJ,result);rn FDZ=FeiDiZeng(result);rn FDJ=FeiDiJian(result);rn rn printf("%04d - %04d = %04d\n",FDZ,FDJ,FDZ-FDJ);rnrn rnrnrnrn```rn rn```

C++的问题，提交了是Time Limit Exceeded，求解？
[img=https://img-bbs.csdn.net/upload/201809/05/1536110393_136531.png][/img] include include using namespace std; class complex { public: complex(){} complex(double m,double n) { this-&amp;amp;gt...

Time to live exceeded，什么原因？
Linux下使用ping命令ping另一solaris主机，返回rnFrom 192.168.2.1 icmp_seq=0 Time to live exceededrnFrom 192.168.2.1 icmp_seq=1 Time to live exceededrnFrom 192.168.2.1 icmp_seq=2 Time to live exceededrnFrom 192.168.2.1 icmp_seq=3 Time to live exceededrn另使用telnet命令，返回rntelnet: Unable to connect to remote host: No route to hostrn----rn本人对网络什么的是菜鸟，还请各位大虾指点指点
Time to live exceeded ，什么原因？
Linux下使用ping命令ping另一solaris主机，返回 ：rnFrom 192.168.2.1 icmp_seq=0 Time to live exceeded rnFrom 192.168.2.1 icmp_seq=1 Time to live exceeded rnFrom 192.168.2.1 icmp_seq=2 Time to live exceeded rnFrom 192.168.2.1 icmp_seq=3 Time to live exceeded rnrn另使用telnet命令，返回 ：rntelnet: Unable to connect to remote host: No route to host rn---- rn上面是什么原因，还请各位大虾指点指点
Time to live exceeded怎么办

compiler table limit exceeded?为什么？

Time Limit Exceed求助
http://acm.scs.bupt.cn/onlinejudge/newoj/showProblem/show_problem.php?problem_id=67rn上边链接是题目rnrn[size=16px]以下是超时代码，能给改改不？要不给个不超时的？[/size]rn#include rn#include rn#include rnusing namespace std;rnrnint main()rnrn int n;rn vector v;rn while(scanf("%d",&n)!=EOF)rn rn for(int i=0;i>x;rn if(x==1)rn rn cin>>y;rn v.push_back(y);rn rn else rn rn sort(v.begin(),v.end());rn if(v.size()%2==1)rn rn int p=(v.size()-1)/2;rn printf("%.1f",v[p]);//长度为基数rn printf("\n");rn rn rn else rn rn int m=v.size()/2;rn int l=m-1;rn double u=(v[m]+v[l])/2;rn cout.precision(1);rn printf("%.1f",u);rn printf("\n");rn rn rn rn rn return 0;rn

#1148 : 2月29日rn时间限制:2000msrn单点时限:1000msrn内存限制:256MBrn描述rn给定两个日期，计算这两个日期之间有多少个2月29日（包括起始日期）。rn只有闰年有2月29日，满足以下一个条件的年份为闰年：rn1. 年份能被4整除但不能被100整除rn2. 年份能被400整除rnrn输入rn第一行为一个整数T，表示数据组数。rn之后每组数据包含两行。每一行格式为"month day, year"，表示一个日期。month为"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November" , "December"中的一个字符串。day与year为两个数字。rn数据保证给定的日期合法且第一个日期早于或等于第二个日期。rnrn输出rn对于每组数据输出一行，形如"Case #X: Y"。X为数据组数，从1开始，Y为答案。rn数据范围rn1 ≤ T ≤ 550rn小数据：rn2000 ≤ year ≤ 3000rn大数据：rn2000 ≤ year ≤ 2×109rnrn样例输入rn4rnJanuary 12, 2012rnMarch 19, 2012rnAugust 12, 2899rnAugust 12, 2901rnAugust 12, 2000rnAugust 12, 2005rnFebruary 29, 2004rnFebruary 29, 2012rn样例输出rnCase #1: 1rnCase #2: 0rnCase #3: 1rnCase #4: 3rn以下是我的代码rn[code=c]//判断year1+1和year2-1之间有几个闰年，再分别判断两个端点。rn#includern#includernusing namespace std;rnstring month[12]="January","February","March","April","May","June","July","August","September","October","November","December";rnbool is_leapyear(int y)rnrn if((y%4==0&&y%100!=0)||(y%400==0))rn rn return 1;rn rn elsern return 0;rnrnint main()rnrn int T;rn cin>>T;rn string month1;rn string month2;rn int monthnum1;rn int monthnum2;rn int day1;rn int day2;rn int year1;rn int year2;rn char comma;rn int leapyear_num=0;rn for(int i=0;i>month1>>day1>>comma>>year1;rn cin>>month2>>day2>>comma>>year2;rn for(int j=0;j<12;j++) //把string类型的月份转成int型月份号rn rn if(month[j]==month1)rn rn monthnum1=j+1;rn rn if(month[j]==month2)rn rn monthnum2==j+1;rn rn rn if(year1==year2&&is_leapyear(year1))rn rn if(monthnum1<=2&&monthnum2>2)rn rn leapyear_num=1;rn rn else if(monthnum1<=2&&(monthnum2==2&&day2==29))rn rn leapyear_num=1;rn rn rn if(year12||(monthnum2==2&&day2==29)))rn rn leapyear_num++;rn rn rn cout<<"Case #"<
time limit 的问题

zoj_1649出现Memory Limit Exceeded，各位大牛帮帮忙啊

compiler limit : debug information module size exceeded

1.服务器相关配置问题通过修改开发坏境IDE运行参数或者线上环境启动修改配置-Xmx768m来扩大允许占用内存大小2.程序存在相应对象无法被GC垃圾回收处理程序部分代码BUG导致内存溢出，GC无法做出处理，我们需要借助工具来分析在哪里出现这样的问题。JDK的jhat命令能帮助我们。查看jhat展示的网页信息中，一般查看堆异常情况主要看这个两个部分： Show instance counts for...
JAVA ArrayList GC overhead limit exceeded问题

Output Limit Exceeded问题 3Sum leetcode
leetcode问题3Sum：rnGiven an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.rnrnNote:rnElements in a triplet (a,b,c) must be in non-descending order. (ie, a ≤ b ≤ c)rnThe solution set must not contain duplicate triplets.rn For example, given array S = -1 0 1 2 -1 -4,rnrn A solution set is:rn (-1, 0, 1)rn (-1, -1, 2)rn以下是我对此题的解法，复杂度为O(n*n) 应该可以通过，在vs2012上也没问题，但是提交后显示 Output Limit Exceeded。百思不得错误出处，求大神指点。 rnrn vector > threeSum(vector &num) rn int n=num.size();rn vector > v;rn if(n<3) return v;rn sort(num.begin(),num.end());rn int sum=0,i,ibegin,iend,target=0;rn rn vector c(3); rn for(i=0;i

compile table limit exceeded,可能是什么问题?

acm 总是Time Limit Exceed！！！！！！！！！！！
DescriptionnnThe 36th ACM match was hosted in Chengdu in 2011 Nov 4. There is an interesting rule in ACM match that once you solve a problem, you'll get a balloon.nnTo simplify these names, we just name these teams S1, S2, S3 ... SN.nnWe want to know how many balloons they get between team Si and Sj (including Si and Sj). We may ask many times. It is too boring to count every time.nnSince you are a programmer, can you write a program to solve it?nnInputnnFirst is an integer N (1 <= N <= 140) indicates the number of schools.nnFollowed with an integer M (1 <= M <= 50000) indicates the number of operations.nnThere are two kinds of operations.nnAC Xnn Means team SX solve a problem and will get a balloon.nnCOUNT X Ynn Means count balloons of team between SX and SYnnOutputnnFor each operation "COUNT X Y" output the number you countnnSample Inputn5 4nAC 1nCOUNT 1 3nAC 2nCOUNT 1 3nSample Outputn1n2nnn我的程序：n#includen#includen#include nusing namespace std;nint main()nn int b,a;n scanf("%d%d",&b,&a);n int *c=new int[b];n for(int j=0;j>d;n if(d=="AC")n n scanf("%d",&g);n c[g-1]++;n else if(d=="COUNT")n n scanf("%d%d",&p,&f);n int sum=0;n for(int i=p-1;i
Python下的整数的因式分解
Python的因式分解，先上传一下代码，以后再说思路 a=int(input(‘please input a number’)) i=2 c=a ls=[] while i&lt;a: if a%i==0: a=a/i ls.append(i) i=2 else:i=i+1 ls.append(round(a)) o=1 while o&lt;len(ls): ls.insert(o,‘×’) o...