您的位置:首页 > 编程语言 > C语言/C++

C++ 中的名称冲突之 "y1"

2016-05-23 01:16 816 查看

已经是第二次遇到这个问题了:

#include <bits/stdc++.h>
using namespace std;

const int N(105);

int dp
[2]
[2]
;
int x1, x2, y1, y2;

int dfs(int x1, int s, int x2, int t, int y){
int & now=dp[x1][s][x2][t][y];
if(~now) return now;
int sum=0, cnt=0;
if(s==0){
sum+=dfs(x1, 1, x2, t, y-1), cnt++;
if(t==0)
sum+=dfs(x1, s, x2, 1, y-1), cnt++;
else if(x2>0)
sum+=dfs(x1, 0, x2-1, t, y), cnt++;
}
else{
if(x1>0) sum+=dfs(x1-1, s, x2, t, y), cnt++;
if(t==0)
sum+=dfs(x1, s, x2, 1, y-1), cnt++;
else if(x2>0)
sum+=dfs(x1, s, x2-1, t, y), cnt++;
}

if((y1+1)*(1-s)+(y2+1)*(1-t)< y) //forbidden numbers;
sum+=dfs(x1, s, x2, t, y-1), cnt++;

return now = sum!=cnt;
}

int a
;

int main(){
int T;
int n;
for(cin>>T; T--; ){
cin>>n;
int p;
for(int i=0; i<n; i++){
cin>>a[i];
if(a[i]==1) p=i;
}
x1=0, x2=0, y1=0, y2=0;
int i;

for(i=p-1; i>=0 && a[i]>a[i+1]; i--, x1++);

for(; i>=0 && a[i]<a[i+1]; i--, y1++);
for(i=p+1; i<n && a[i]>a[i-1]; i++, x2++);
for(; i<n && a[i]<a[i-1]; i++, y2++);

memset(dp, -1, sizeof(dp));
x1=max(x1-1, 0), x2=max(x2-1, 0);

// cout<<x1<<' '<<x2<<' '<<y1<<' '<<y2<<endl;
int peak=(p!=0) + (p!=n-1);
for(int i=0; i<=n-1-x1-x2-peak; i++)
dp[0][1][0][1][i]=1;    //error-prone

int s=p==0, t=p==n-1;   //error-prone

int res=dfs(x1, s, x2, t, n-1-x1-x2);
// cout<<res<<endl;
puts(res==1?"Alice": "Bob");
}
return 0;
}

 

试图在终端编译,运行: (gcc version 4.8.4)

g++ main.cpp -std=c++11 -o main && ./main <in

返回结果:

main.cpp:8:13: error: ‘int y1’ redeclared as different kind of symbol
int x1, x2, y1, y2;
^
In file included from /usr/include/features.h:374:0,
from /usr/include/assert.h:35,
from /usr/include/c++/4.8/cassert:43,
from /usr/include/x86_64-linux-gnu/c++/4.8/bits/stdc++.h:33,
from main.cpp:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:241:1: error: previous declaration of ‘double y1(double)’
__MATHCALL (y1,, (_Mdouble_));
^

显示变量y1 和C++标准库中的某个变量名称冲突,这个问题应当引起注意。

另外这不是头文件写成<bits/stdc++.h>引起的,即使换成各具体的头文件(<iostream>, <algorithm>, <ctring>)还是会返回这个错误。

具体原因及解决办法还有待研究。

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: