May the force be with you!
R2

R2
posts - 51,  comments - 19,  trackbacks - 0
按照lzx大牛推荐的分类,开始写搜索题,发现这道1426是个很典型的BFS,写完交上去,结果RE,原来是队列长度开的不够,于是加长了点,就 125ms过了,可是内存太大,用了8000多k,不知道大牛们是怎么用0ms,40多k过得。。。貌似还有DP的写法?好像还有什么构造法。。。我压根 就不知道什么是构造法。。。期待大牛解释。。。
                            Simbaforrest
                            2008.1.9
 1 #include<iostream>
 2 #include<cstring>
 3 #include<cmath>
 4 using namespace std;
 5 int n;
 6 const int maxn = 1100000;
 7 __int64 q[maxn];
 8 
 9 void BFS()
10 {
11     //init
12     int front,rear;
13     front=rear=0;
14     q[rear]=1;
15     rear++;
16     //sovle
17     __int64 top;
18     while(rear>front)
19     {
20         top = q[front];
21         if(top%n==0)
22             break;
23         top *= 10;
24         q[rear++]=top;
25         q[rear++]=top+1;
26         front++;
27     }
28     //output
29     cout<<top<<endl;
30 }
31 
32 int main()
33 {
34     while(cin>>n&&n!=0)
35     {
36         BFS();
37     }
38     return 0;
39 }
40 

posted on 2008-01-09 14:32 R2 阅读(422) 评论(0)  编辑 收藏 引用 所属分类: Problem Solving

标题  
姓名  
主页
验证码 *
内容(提交失败后,可以通过“恢复上次提交”恢复刚刚提交的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
[使用Ctrl+Enter键可以直接提交]
相关链接:
网站导航:



你是第 free hit counter 位访客


联系博主


<2008年1月>
303112345
6789101112
13141516171819
20212223242526
272829303112
3456789

常用链接

留言簿(1)

随笔分类(56)

随笔档案(51)

文章档案(1)

ACM/ICPC

技术综合

最新随笔

搜索

  •  

积分与排名

  • 积分 - 17219
  • 排名 - 133

最新评论

阅读排行榜

评论排行榜