急 在线等 为什么这个C++代码在vc6下编译错误?
错误原因errorC2872:'count':ambiguoussymbol我count[]定义了的啊什么情况?代码:#include<iostream>#include...
错误原因
error C2872: 'count' : ambiguous symbol
我count[]定义了的啊什么情况?
代码:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
#define MAX 5000
struct IN
{
int pos,value;
};
IN number[MAX+100];
int tree[MAX+100];
int count[MAX+100];
int inverse[MAX+100];
int n,sum,maxx;
int lowbit(int x)
{
return x & (-x);
}
void Input()
{
for(int i=1;i<=n;i++)
{
scanf("%d",&number[i].value);
number[i].pos=i;
}
}
int cmp(const IN &a,const IN &b)
{
return a.value<b.value;
}
void Counfill(int *count)
{
int p=1;
count[number[1].pos]=1;
for(int i=2;i<=n;i++)
{
if(number[i].value==number[i-1].value)
count[number[i].pos]=p;
else
count[number[i].pos]=++p;
}
}
void modify(int x,int num)
{
for(int i=x;i<=n;i+=lowbit(i))
{
tree[i]+=num;
}
}
int Getsum(int x)
{
int s=0;
for(int i=x;i>0;i-=lowbit(i))
{
s+=tree[i];
}
return s;
}
void Stats(int *count)
{
sum=0;
maxx=-1;
for(int i=1;i<=n;i++)
{
modify(count[i],1);
inverse[i]=Getsum(count[i]);
sum+=i-inverse[i];
}
maxx=sum;
}
void Cirans()
{
for(int i=n;i>=1;i--)
{
sum=sum-i+2*inverse[i];
if(maxx<sum)
maxx=sum;
}
}
int main()
{
while(~scanf("%d",&n))
{
memset(tree,0,sizeof(tree));
memset(inverse,0,sizeof(inverse));
Input();
sort(number+1,number+1+n,cmp);
Counfill(count);
Stats(count);
Cirans();
printf("%d\n",maxx);
}
return 0;
} 展开
error C2872: 'count' : ambiguous symbol
我count[]定义了的啊什么情况?
代码:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
#define MAX 5000
struct IN
{
int pos,value;
};
IN number[MAX+100];
int tree[MAX+100];
int count[MAX+100];
int inverse[MAX+100];
int n,sum,maxx;
int lowbit(int x)
{
return x & (-x);
}
void Input()
{
for(int i=1;i<=n;i++)
{
scanf("%d",&number[i].value);
number[i].pos=i;
}
}
int cmp(const IN &a,const IN &b)
{
return a.value<b.value;
}
void Counfill(int *count)
{
int p=1;
count[number[1].pos]=1;
for(int i=2;i<=n;i++)
{
if(number[i].value==number[i-1].value)
count[number[i].pos]=p;
else
count[number[i].pos]=++p;
}
}
void modify(int x,int num)
{
for(int i=x;i<=n;i+=lowbit(i))
{
tree[i]+=num;
}
}
int Getsum(int x)
{
int s=0;
for(int i=x;i>0;i-=lowbit(i))
{
s+=tree[i];
}
return s;
}
void Stats(int *count)
{
sum=0;
maxx=-1;
for(int i=1;i<=n;i++)
{
modify(count[i],1);
inverse[i]=Getsum(count[i]);
sum+=i-inverse[i];
}
maxx=sum;
}
void Cirans()
{
for(int i=n;i>=1;i--)
{
sum=sum-i+2*inverse[i];
if(maxx<sum)
maxx=sum;
}
}
int main()
{
while(~scanf("%d",&n))
{
memset(tree,0,sizeof(tree));
memset(inverse,0,sizeof(inverse));
Input();
sort(number+1,number+1+n,cmp);
Counfill(count);
Stats(count);
Cirans();
printf("%d\n",maxx);
}
return 0;
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询