Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:这样改完为什么就错了?In Reply To:这样改完为什么就错了? Posted by:billmaths at 2005-03-31 20:16:14 > 我用的线段树,存储用的数组 > struct node { > int v;//结点的值 > int c;//存储在此结点子孙的star个数;函数更改后表示小与等于此结点的v的结点个数 > int l,r;//左右子树指针 > }tree[32002]; > > 主函数中函数调用语句: > scanf("%d",&n); > for (i = 0; i < n; i++) { > scanf("%d %d",&x,&y); > res[count(Root,x)]++; //计算小与x的结点个数 > insert(x); //插入结点,值为x > } > > > 可以AC的函数: > int count(int root, int x) { > if (tree[root].v == x) > return tree[root].c - tree[tree[root].r].c; //* > else if (tree[root].v < x) > return tree[root].c - tree[tree[root].r].c + count(tree[root].r,x); //* > else //tree[r].v > x > return count(tree[root].l,x); > } > > void insert(int x) { > int p = Root; > while (x != tree[p].v) { > tree[p].c++; //* > if (x < tree[p].v) p = tree[p].l; > else p = tree[p].r; > } > tree[p].c++; > } > > 更改后WA的函数:(标*的语句是修改的位置) > int count(int root, int x) { > if (tree[root].v == x) > return tree[root].c; //* > else if (tree[root].v < x) > return tree[root].c + count(tree[root].r,x); //* > else //tree[r].v > x > return count(tree[root].l,x); > } > > void insert(int x) { > int p = Root; > while (x != tree[p].v) { > if (x < tree[p].v) { > tree[p].c++; //* > p = tree[p].l; > } > else p = tree[p].r; > } > tree[p].c++; > } > > 想不明白为什么改完了就错了,请路过的帮我看一下,谢谢~~~ Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator