早有耳闻,C++的不怎么好~~
一直都还不太相信。。
今天倒是亲眼目睹了我的错误~.~
在做RQNOJ的第
133题得时候我用C++的I/O做的,80......
看下:
1 #include <iostream>
2 using namespace std;
3 struct
4 {
5 long d;
6 Tree *R,*L;
7 long sum;
8 }*T=NULL,*Node=NULL;
9
10 void Insert(Tree *&T,Tree *Node)
11 {
12 if(T==NULL)
13 {
14 T=Node;
15 T->sum=1;
16 return;
17 }
18 if(Node->d<=T->d)
19 {
20 if(Node->d==T->d)
21 {
22 T->sum++;
23 }
24 else
25 Insert(T->L,Node);
26 }
27 else
28 Insert(T->R,Node);
29 }
30
31 void Print(Tree *T)
32 {
33 if(T==NULL)
34 return;
35 Print(T->L);
36 cout<d<<" "<sum<R);
37 }
38 int main()
39 {
40 long n,t;
41 cin>>n;
42 while(n>0)
43 {
44 cin>>t;
45 Node=new Tree;
46 Node->d=t;
47 Node->R=NULL;
48 Node->L=NULL;
49 Insert(T,Node);
50 n--;
51 }
52 Print(T);
53 return 0;
54 }
55
状态: Unaccepted
测评机: Xeond[6]
得分: 80分
提交日期: 2008-8-18 18:26:00
有效耗时: 1860毫秒
测试结果1: 通过本测试点有效耗时63:ms
测试结果2: 通过本测试点有效耗时62:ms
测试结果3: 通过本测试点有效耗时94:ms
测试结果4: 通过本测试点有效耗时109:ms
测试结果5: 通过本测试点有效耗时422:ms
测试结果6: 通过本测试点有效耗时594:ms
测试结果7: 通过本测试点有效耗时469:ms
测试结果8: 选手程序运行超过时限
测试结果9: 选手程序运行超过时限
测试结果10: 通过本测试点有效耗时47:ms
而后用C的I/O做的:
1 #include <stdio.h>
2 struct Tree
3 {
4 long d;
5 Tree *R,*L;
6 long sum;
7 }*T=NULL,*Node=NULL;
8
9 void Insert(Tree *&T,Tree *Node)
10 {
11 if(T==NULL)
12 {
13 T=Node;
14 T->sum=1;
15 return;
16 }
17 if(Node->d<=T->d)
18 {
19 if(Node->d==T->d)
20 {
21 T->sum++;
22 }
23 else
24 Insert(T->L,Node);
25 }
26 else
27 Insert(T->R,Node);
28 }
29
30 void Print(Tree *T)
31 {
32 if(T==NULL)
33 return;
34 Print(T->L);
35 printf("%ld %ld\n",T->d,T->sum);
36 Print(T->R);
37 }
38 int main()
39 {
40 long n,t;
41 scanf("%ld",&n);
42 while(n>0)
43 {
44 scanf("%ld",&t);
45 Node=new Tree;
46 Node->d=t;
47 Node->R=NULL;
48 Node->L=NULL;
49 Insert(T,Node);
50 n--;
51 }
52 Print(T);
53 return 0;
54 }
55
状态: Accepted
测评机: Xeond[6]
得分: 100分
提交日期: 2008-8-18 18:37:00
有效耗时: 1217毫秒
测试结果1: 通过本测试点有效耗时62:ms
测试结果2: 通过本测试点有效耗时46:ms
测试结果3: 通过本测试点有效耗时47:ms
测试结果4: 通过本测试点有效耗时63:ms
测试结果5: 通过本测试点有效耗时109:ms
测试结果6: 通过本测试点有效耗时141:ms
测试结果7: 通过本测试点有效耗时125:ms
测试结果8: 通过本测试点有效耗时312:ms
测试结果9: 通过本测试点有效耗时265:ms
测试结果10: 通过本测试点有效耗时47:ms
不知道你们注意吗,在用C输出的时候最大耗时是312ms,而C++....我不想再说什么了~~
以后学C++的朋友要注意,最好要用C的O/I。。
终于AC了。。。
有些题目是没什么错,但是要考虑时空的。。
..