Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:各位大虾帮忙看怎么优化啊

Posted by Ask at 2003-10-14 19:38:44 on Problem 1002
In Reply To:Re:各位大虾帮忙看怎么优化啊 Posted by:kevingl at 2003-10-14 12:51:34
我没有细看你的程序,不过就你输出的这一段:
long?tempa=a[i]/10000,tempb=a[i]%10000; 
????????cout<<tempa/100;tempa=tempa%100; 
????????cout<<tempa/10;tempa=tempa%10; 
????????cout<<tempa<<'-'; 
????????cout<<tempb/1000;tempb=tempb%1000; 
????????cout<<tempb/100;tempb=tempb%100; 
????????cout<<tempb/10;tempb=tempb%10; 
????????cout<<tempb<<'?'<<max<<endl; 

每输出一个数你要做6次除法和6次求模。这个是非常慢的,你可以试试做100000次求模比做100000次加法要慢多少。

而你这段语句完全可以用C++里的输出控制符达到同样的功能,C里也是有的
如我程序里的:
cout<<setfill('0')<<setw(3)<<last/10000;
cout<<'-'<<setfill('0')<<setw(4)<<last%10000;

一次除法和求模就够了,改过来应该就可以了吧

当然前提是你的程序里没有死循环……

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator